Project

General

Profile

« Previous | Next » 

Revision 261548ff

Added by koszko about 2 years ago

emply an sh-based build system; make some changes to blocking

View differences:

content/page_actions.js
5 5
 * Redistribution terms are gathered in the `copyright' file.
6 6
 */
7 7

  
8
"use strict";
9

  
10
(() => {
11
    const CONNECTION_TYPE = window.CONNECTION_TYPE;
12
    const browser = window.browser;
13

  
14
    var port;
15
    var loaded = false;
16
    var scripts_awaiting = [];
17
    var nonce;
8
/*
9
 * IMPORTS_START
10
 * IMPORT CONNECTION_TYPE
11
 * IMPORT browser
12
 * IMPORTS_END
13
 */
18 14

  
19
    function handle_message(message)
20
    {
21
	console.log(["message", message]);
15
var port;
16
var loaded = false;
17
var scripts_awaiting = [];
18
var nonce;
22 19

  
23
	if (message.inject === undefined)
24
	    return;
20
function handle_message(message)
21
{
22
    if (message.inject === undefined)
23
	return;
25 24

  
26
	for (let script_text of message.inject) {
27
	    if (loaded)
28
		add_script(script_text);
29
	    else
30
		scripts_awaiting.push(script_text);
31
	}
25
    for (let script_text of message.inject) {
26
	if (loaded)
27
	    add_script(script_text);
28
	else
29
	    scripts_awaiting.push(script_text);
32 30
    }
31
}
33 32

  
34
    function document_loaded(event)
35
    {
36
	console.log("loaded");
37

  
38
	loaded = true;
33
function document_loaded(event)
34
{
35
    loaded = true;
39 36

  
40
	for (let script_text of scripts_awaiting)
41
	    add_script(script_text);
37
    for (let script_text of scripts_awaiting)
38
	add_script(script_text);
42 39

  
43
	scripts_awaiting = undefined;
44
    }
40
    scripts_awaiting = undefined;
41
}
45 42

  
46
    function add_script(script_text)
47
    {
48
	let script = document.createElement("script");
49
	script.textContent = script_text;
50
	script.setAttribute("nonce", nonce);
51
	document.body.appendChild(script);
52
    }
43
function add_script(script_text)
44
{
45
    let script = document.createElement("script");
46
    script.textContent = script_text;
47
    script.setAttribute("nonce", nonce);
48
    document.body.appendChild(script);
49
}
53 50

  
54
    function handle_page_actions(script_nonce) {
55
	document.addEventListener("DOMContentLoaded", document_loaded);
56
	port = browser.runtime.connect({name : CONNECTION_TYPE.PAGE_ACTIONS});
57
	port.onMessage.addListener(handle_message);
58
	port.postMessage({url: document.URL});
51
function handle_page_actions(script_nonce) {
52
    document.addEventListener("DOMContentLoaded", document_loaded);
53
    port = browser.runtime.connect({name : CONNECTION_TYPE.PAGE_ACTIONS});
54
    port.onMessage.addListener(handle_message);
55
    port.postMessage({url: document.URL});
59 56

  
60
	nonce = script_nonce;
61
    }
57
    nonce = script_nonce;
58
}
62 59

  
63
    window.handle_page_actions = handle_page_actions;
64
})();
60
/*
61
 * EXPORTS_START
62
 * EXPORT handle_page_actions
63
 * EXPORTS_END
64
 */

Also available in: Unified diff