Revision 261548ff
Added by koszko about 2 years ago
background/main.js | ||
---|---|---|
5 | 5 |
* Redistribution terms are gathered in the `copyright' file. |
6 | 6 |
*/ |
7 | 7 |
|
8 |
"use strict"; |
|
9 |
|
|
10 |
(() => { |
|
11 |
const TYPE_PREFIX = window.TYPE_PREFIX; |
|
12 |
const get_storage = window.get_storage; |
|
13 |
const start_storage_server = window.start_storage_server; |
|
14 |
const start_page_actions_server = window.start_page_actions_server; |
|
15 |
const start_policy_injector = window.start_policy_injector; |
|
16 |
const browser = window.browser; |
|
17 |
|
|
18 |
start_storage_server(); |
|
19 |
start_page_actions_server(); |
|
20 |
start_policy_injector(); |
|
21 |
|
|
22 |
async function init_myext(install_details) |
|
23 |
{ |
|
24 |
console.log("details:", install_details); |
|
25 |
if (install_details.reason != "install") |
|
26 |
return; |
|
27 |
|
|
28 |
let storage = await get_storage(); |
|
29 |
|
|
30 |
await storage.clear(); |
|
31 |
|
|
32 |
/* |
|
33 |
* Below we add sample settings to the extension. |
|
34 |
* Those should be considered example values for viewing in the options |
|
35 |
* page. They won't make my.fsf.org work. The only scripts that does |
|
36 |
* something useful right now is the opencores one. |
|
37 |
*/ |
|
38 |
|
|
39 |
let components = []; |
|
40 |
for (let script_data of [ |
|
41 |
{url: "http://127.0.0.1:8000/myfsf_define_CRM.js", |
|
42 |
hash:"bf0cc81c7e8d5f800877b4bc3f14639f946f5ac6d4dc120255ffac5eba5e48fe"}, |
|
43 |
{url: "https://my.fsf.org/misc/jquery.js?v=1.4.4", |
|
44 |
hash:"261ae472fa0cbf27c80c9200a1599a60fde581a0e652eee4bf41def8cb61f2d0"}, |
|
45 |
{url: "https://my.fsf.org/misc/jquery-extend-3.4.0.js?v=1.4.4", |
|
46 |
hash:"c54103ba57ee210ca55c052e70415402707548a4e6a68dd6efb3895019bee392"}, |
|
47 |
{url: "https://my.fsf.org/misc/jquery-html-prefilter-3.5.0-backport.js?v=1.4.4", |
|
48 |
hash:"fad84efa145fb507e5df9b582fa01b1c4e6313de7f72ebdd55726d92fa4dbf06"}, |
|
49 |
{url: "https://my.fsf.org/misc/jquery.once.js?v=1.2", |
|
50 |
hash:"1430f42c0d760ba8e05bb3762480502e541f654fec5739ee40625ab22dc38c4f"}, |
|
51 |
{url: "https://my.fsf.org/misc/drupal.js?qmaukd", |
|
52 |
hash:"2e08dccbd4d8b728a6871562995a4636b89bfe0ed3b8fb0138191c922228b116"}, |
|
53 |
{url: "https://my.fsf.org/sites/all/modules/civicrm/bower_components/jquery/dist/jquery.min.js?qmaukd", |
|
54 |
hash:"a6d01520d28d15dbe476de84eea90eb3ee2d058722efc062ec73cb5fad78a17b"}, |
|
55 |
{url: "https://my.fsf.org/sites/all/modules/civicrm/bower_components/jquery-ui/jquery-ui.min.js?qmaukd", |
|
56 |
hash:"28ce75d953678c4942df47a11707a15e3c756021cf89090e3e6aa7ad6b6971c3"}, |
|
57 |
{url: "https://my.fsf.org/sites/all/modules/civicrm/bower_components/lodash-compat/lodash.min.js?qmaukd", |
|
58 |
hash:"f2871cc80c52fe8c04c582c4a49797c9c8fd80391cf1452e47f7fe97835ed5cc"}, |
|
59 |
{url: "https://my.fsf.org/sites/all/modules/civicrm/packages/jquery/plugins/jquery.mousewheel.min.js?qmaukd", |
|
60 |
hash:"f50233e84c2ac7ada37a094d3f7d3b3f7c97716d6b7b47bf69619d93ee4ac1ce"}, |
|
61 |
{url: "https://my.fsf.org/sites/all/modules/civicrm/bower_components/select2/select2.min.js?qmaukd", |
|
62 |
hash:"ce61298fb9aa4ec49ccd4172d097e36a9e5db3af06a7b82796659368f15b7c1b"}, |
|
63 |
{url: "https://my.fsf.org/sites/all/modules/civi crm/packages/jquery/plugins/jquery.form.min.js?qmaukd", |
|
64 |
hash:"c90f0e501d2948fbc2b61bffd654fa4ab64741fd48923782419eeb14d3816fb8"}, |
|
65 |
{url: "https://my.fsf.org/sites/all/modules/civicrm/packages/jquery/plugins/jquery.timeentry.min.js?qmaukd", |
|
66 |
hash:"8e85df981e8ad7049d06dfb075277d038734d36a7097c7f021021b2bdccfe9bb"}, |
|
67 |
{url: "https://my.fsf.org/sites/all/modules/civicrm/packages/jquery/plugins/jquery.blockUI.min.js?qmaukd", |
|
68 |
hash:"806aedff52ac822f2adc5797073e1e5c5cec32eb9f15f2319cb32a347dcd232b"}, |
|
69 |
{url: "https://my.fsf.org/sites/all/modules/civicrm/bower_components/datatables/media/js/jquery.dataTables.min.js?qmaukd", |
|
70 |
hash:"b796504d9b1b422f0dc6ccc2d740ac78a8c9e5078cc3934836d39742b1121925"}, |
|
71 |
{url: "https://my.fsf.org/sites/all/modules/civicrm/bower_components/jquery-validation/dist/jquery.validate.min.js?qmaukd", |
|
72 |
hash:"f0f5373ad203101ea91bf826c5a7ef8f7cd74887f06bad2cb9277a504503b9e2"}, |
|
73 |
{url: "https://my.fsf.org/sites/all/modules/civicrm/packages/jquery/plugins/jquery.ui.datepicker.validation.min.js?qmaukd", |
|
74 |
hash:"c6e6f6bf7f8fff25cca338045774e267e8eaa2d48ac9100540f3d59a6d2b3c61"}, |
|
75 |
{url: "https://my.fsf.org/sites/all/modules/civicrm/js/Common.js?qmaukd", |
|
76 |
hash:"17aa222a3af2e8958be16accb5e77ef39f67009cb3b500718d8fffd45b399148"}, |
|
77 |
{url: "https://my.fsf.org/sites/all/modules/civicrm/js/crm.datepicker.js?qmaukd", |
|
78 |
hash:"9bd8d10208aa99c156325f7819da6f0dd62ba221ac4119c3ccd4834e2cf36535"}, |
|
79 |
{url: "https://my.fsf.org/sites/all/modules/civicrm/js/crm.ajax.js?qmaukd", |
|
80 |
hash:"6401a4e257b7499ae4a00be2c200e4504a2c9b3d6b278a830c31a7b63374f0fe"}, |
|
81 |
{url: "https://my.fsf.org/sites/all/modules/civicrm/js/wysiwyg/crm.wysiwyg.js?qmaukd", |
|
82 |
hash:"fa962356072a36672c3b4b25bdeb657f020995a067e20a29cd5bb84b05157762"}, |
|
83 |
{url: "https://my.fsf.org/sites/all/modules/civicrm/js/noconflict.js?qmaukd", |
|
84 |
hash:"58d6d9f496a235d23cf891926d71f2104e4f2afe1d14bb4e2b5233f646c35e62"}, |
|
85 |
{url: "https://my.fsf.org/sites/all/modules/matomo/matomo.js?qmaukd", |
|
86 |
hash:"7f39ccd085f348189cd2fb62ea4d4a658d96f6bba266265880b98605e777e2de"}, |
|
87 |
{url: "https://my.fsf.org/sites/all/themes/fsf_venture/js/global.js?qmaukd", |
|
88 |
hash:"aa7983f6b902f9f4415cfc8346e0c3f194cc95b78f52f2ad09ec7effa1326b9c"}, |
|
89 |
{url: "https://my.fsf.org/sites/all/themes/fsf_venture/js/jquery.superfish.min.js?qmaukd", |
|
90 |
hash:"5ef1f93bf3901227056bf9ed0ed93a148eec4dda30f419756b12bedd1098815e"}, |
|
91 |
{url: "https://my.fsf.org/sites/all/themes/fsf_venture/js/jquery.sidr.min.js?qmaukd", |
|
92 |
hash:"c4914d415826676c6af2e61f16edb72c5388f8600ba6de9049892aee49d980a0"}, |
|
93 |
{url: "https://my.fsf.org/sites/all/themes/fsf_venture/js/jquery.flexslider.min.js?qmaukd", |
|
94 |
hash:"cefaf715761b4494913851249b9d40dacb4a8cb61242b0efc859dc586d56e0d4"}, |
|
95 |
{url: "http://127.0.0.1:8000/myfsf_crap.js", |
|
96 |
hash:"d91ccf21592d0f861ea0ba946bc257fc5d88269327cad0a91387da6cb8ff633e"}, |
|
97 |
{url: "https://my.fsf.org/sites/all/modules/civicrm/templates/CRM/Core/BillingBlock.js?r=lp7Di", |
|
98 |
hash:"2f25d35e7a0c0060ab0a444a577f09dd3c9934ae898a7ee0eb20b6c986ab5a1c"}, |
|
99 |
{url: "https://my.fsf.org/extensions/com.aghstrategies.giftmemberships/js/giftpricefield.js?r=lp7Di", |
|
100 |
hash:"f86080e6bd306fe46474039aeca2808235005bce5a2a29416d08210022039a45"}, |
|
101 |
{url: "https://my.fsf.org/extensions/com.ginkgostreet.negativenegator/js/negativenegator.js?r=lp7Di", |
|
102 |
hash:"d0e87bac832856db70947d82a7ab4e0b7c8b1070d5f1a32335345e033ece3a14"} |
|
103 |
]) { |
|
104 |
let name_regex = /\/([^/]+)\.js/; |
|
105 |
let name = name_regex.exec(script_data.url)[1]; |
|
106 |
await storage.set(TYPE_PREFIX.SCRIPT, name, script_data); |
|
107 |
components.push([TYPE_PREFIX.SCRIPT, name]); |
|
108 |
} |
|
109 |
|
|
110 |
await storage.set(TYPE_PREFIX.BAG, "myfsf_join", components); |
|
111 |
|
|
112 |
await storage.set(TYPE_PREFIX.PAGE, "https://my.fsf.org/join", { |
|
113 |
components: [TYPE_PREFIX.BAG, "myfsf_join"] |
|
114 |
}); |
|
115 |
|
|
116 |
let hello_script = { |
|
117 |
text: "console.log(\"hello, every1!\");\n" |
|
118 |
}; |
|
119 |
await storage.set(TYPE_PREFIX.SCRIPT, "hello", hello_script); |
|
120 |
await storage.set(TYPE_PREFIX.BAG, "hello", |
|
121 |
[[TYPE_PREFIX.SCRIPT, "hello"]]); |
|
122 |
await storage.set(TYPE_PREFIX.PAGE, "https://my.fsf.org/", { |
|
123 |
components: [TYPE_PREFIX.BAG, "hello"], |
|
124 |
allow: true |
|
125 |
}); |
|
126 |
|
|
127 |
let opencores_script = { |
|
128 |
text: `\ |
|
8 |
/* |
|
9 |
* IMPORTS_START |
|
10 |
* IMPORT TYPE_PREFIX |
|
11 |
* IMPORT get_storage |
|
12 |
* IMPORT start_storage_server |
|
13 |
* IMPORT start_page_actions_server |
|
14 |
* IMPORT start_policy_injector |
|
15 |
* IMPORT browser |
|
16 |
* IMPORTS_END |
|
17 |
*/ |
|
18 |
|
|
19 |
start_storage_server(); |
|
20 |
start_page_actions_server(); |
|
21 |
start_policy_injector(); |
|
22 |
|
|
23 |
async function init_myext(install_details) |
|
24 |
{ |
|
25 |
console.log("details:", install_details); |
|
26 |
if (install_details.reason != "install") |
|
27 |
return; |
|
28 |
|
|
29 |
let storage = await get_storage(); |
|
30 |
|
|
31 |
await storage.clear(); |
|
32 |
|
|
33 |
/* |
|
34 |
* Below we add sample settings to the extension. |
|
35 |
* Those should be considered example values for viewing in the options |
|
36 |
* page. They won't make my.fsf.org work. The only scripts that does |
|
37 |
* something useful right now is the opencores one. |
|
38 |
*/ |
|
39 |
|
|
40 |
let components = []; |
|
41 |
for (let script_data of [ |
|
42 |
{url: "http://127.0.0.1:8000/myfsf_define_CRM.js", |
|
43 |
hash:"bf0cc81c7e8d5f800877b4bc3f14639f946f5ac6d4dc120255ffac5eba5e48fe"}, |
|
44 |
{url: "https://my.fsf.org/misc/jquery.js?v=1.4.4", |
|
45 |
hash:"261ae472fa0cbf27c80c9200a1599a60fde581a0e652eee4bf41def8cb61f2d0"}, |
|
46 |
{url: "https://my.fsf.org/misc/jquery-extend-3.4.0.js?v=1.4.4", |
|
47 |
hash:"c54103ba57ee210ca55c052e70415402707548a4e6a68dd6efb3895019bee392"}, |
|
48 |
{url: "https://my.fsf.org/misc/jquery-html-prefilter-3.5.0-backport.js?v=1.4.4", |
|
49 |
hash:"fad84efa145fb507e5df9b582fa01b1c4e6313de7f72ebdd55726d92fa4dbf06"}, |
|
50 |
{url: "https://my.fsf.org/misc/jquery.once.js?v=1.2", |
|
51 |
hash:"1430f42c0d760ba8e05bb3762480502e541f654fec5739ee40625ab22dc38c4f"}, |
|
52 |
{url: "https://my.fsf.org/misc/drupal.js?qmaukd", |
|
53 |
hash:"2e08dccbd4d8b728a6871562995a4636b89bfe0ed3b8fb0138191c922228b116"}, |
|
54 |
{url: "https://my.fsf.org/sites/all/modules/civicrm/bower_components/jquery/dist/jquery.min.js?qmaukd", |
|
55 |
hash:"a6d01520d28d15dbe476de84eea90eb3ee2d058722efc062ec73cb5fad78a17b"}, |
|
56 |
{url: "https://my.fsf.org/sites/all/modules/civicrm/bower_components/jquery-ui/jquery-ui.min.js?qmaukd", |
|
57 |
hash:"28ce75d953678c4942df47a11707a15e3c756021cf89090e3e6aa7ad6b6971c3"}, |
|
58 |
{url: "https://my.fsf.org/sites/all/modules/civicrm/bower_components/lodash-compat/lodash.min.js?qmaukd", |
|
59 |
hash:"f2871cc80c52fe8c04c582c4a49797c9c8fd80391cf1452e47f7fe97835ed5cc"}, |
|
60 |
{url: "https://my.fsf.org/sites/all/modules/civicrm/packages/jquery/plugins/jquery.mousewheel.min.js?qmaukd", |
|
61 |
hash:"f50233e84c2ac7ada37a094d3f7d3b3f7c97716d6b7b47bf69619d93ee4ac1ce"}, |
|
62 |
{url: "https://my.fsf.org/sites/all/modules/civicrm/bower_components/select2/select2.min.js?qmaukd", |
|
63 |
hash:"ce61298fb9aa4ec49ccd4172d097e36a9e5db3af06a7b82796659368f15b7c1b"}, |
|
64 |
{url: "https://my.fsf.org/sites/all/modules/civi crm/packages/jquery/plugins/jquery.form.min.js?qmaukd", |
|
65 |
hash:"c90f0e501d2948fbc2b61bffd654fa4ab64741fd48923782419eeb14d3816fb8"}, |
|
66 |
{url: "https://my.fsf.org/sites/all/modules/civicrm/packages/jquery/plugins/jquery.timeentry.min.js?qmaukd", |
|
67 |
hash:"8e85df981e8ad7049d06dfb075277d038734d36a7097c7f021021b2bdccfe9bb"}, |
|
68 |
{url: "https://my.fsf.org/sites/all/modules/civicrm/packages/jquery/plugins/jquery.blockUI.min.js?qmaukd", |
|
69 |
hash:"806aedff52ac822f2adc5797073e1e5c5cec32eb9f15f2319cb32a347dcd232b"}, |
|
70 |
{url: "https://my.fsf.org/sites/all/modules/civicrm/bower_components/datatables/media/js/jquery.dataTables.min.js?qmaukd", |
|
71 |
hash:"b796504d9b1b422f0dc6ccc2d740ac78a8c9e5078cc3934836d39742b1121925"}, |
|
72 |
{url: "https://my.fsf.org/sites/all/modules/civicrm/bower_components/jquery-validation/dist/jquery.validate.min.js?qmaukd", |
|
73 |
hash:"f0f5373ad203101ea91bf826c5a7ef8f7cd74887f06bad2cb9277a504503b9e2"}, |
|
74 |
{url: "https://my.fsf.org/sites/all/modules/civicrm/packages/jquery/plugins/jquery.ui.datepicker.validation.min.js?qmaukd", |
|
75 |
hash:"c6e6f6bf7f8fff25cca338045774e267e8eaa2d48ac9100540f3d59a6d2b3c61"}, |
|
76 |
{url: "https://my.fsf.org/sites/all/modules/civicrm/js/Common.js?qmaukd", |
|
77 |
hash:"17aa222a3af2e8958be16accb5e77ef39f67009cb3b500718d8fffd45b399148"}, |
|
78 |
{url: "https://my.fsf.org/sites/all/modules/civicrm/js/crm.datepicker.js?qmaukd", |
|
79 |
hash:"9bd8d10208aa99c156325f7819da6f0dd62ba221ac4119c3ccd4834e2cf36535"}, |
|
80 |
{url: "https://my.fsf.org/sites/all/modules/civicrm/js/crm.ajax.js?qmaukd", |
|
81 |
hash:"6401a4e257b7499ae4a00be2c200e4504a2c9b3d6b278a830c31a7b63374f0fe"}, |
|
82 |
{url: "https://my.fsf.org/sites/all/modules/civicrm/js/wysiwyg/crm.wysiwyg.js?qmaukd", |
|
83 |
hash:"fa962356072a36672c3b4b25bdeb657f020995a067e20a29cd5bb84b05157762"}, |
|
84 |
{url: "https://my.fsf.org/sites/all/modules/civicrm/js/noconflict.js?qmaukd", |
|
85 |
hash:"58d6d9f496a235d23cf891926d71f2104e4f2afe1d14bb4e2b5233f646c35e62"}, |
|
86 |
{url: "https://my.fsf.org/sites/all/modules/matomo/matomo.js?qmaukd", |
|
87 |
hash:"7f39ccd085f348189cd2fb62ea4d4a658d96f6bba266265880b98605e777e2de"}, |
|
88 |
{url: "https://my.fsf.org/sites/all/themes/fsf_venture/js/global.js?qmaukd", |
|
89 |
hash:"aa7983f6b902f9f4415cfc8346e0c3f194cc95b78f52f2ad09ec7effa1326b9c"}, |
|
90 |
{url: "https://my.fsf.org/sites/all/themes/fsf_venture/js/jquery.superfish.min.js?qmaukd", |
|
91 |
hash:"5ef1f93bf3901227056bf9ed0ed93a148eec4dda30f419756b12bedd1098815e"}, |
|
92 |
{url: "https://my.fsf.org/sites/all/themes/fsf_venture/js/jquery.sidr.min.js?qmaukd", |
|
93 |
hash:"c4914d415826676c6af2e61f16edb72c5388f8600ba6de9049892aee49d980a0"}, |
|
94 |
{url: "https://my.fsf.org/sites/all/themes/fsf_venture/js/jquery.flexslider.min.js?qmaukd", |
|
95 |
hash:"cefaf715761b4494913851249b9d40dacb4a8cb61242b0efc859dc586d56e0d4"}, |
|
96 |
{url: "http://127.0.0.1:8000/myfsf_crap.js", |
|
97 |
hash:"d91ccf21592d0f861ea0ba946bc257fc5d88269327cad0a91387da6cb8ff633e"}, |
|
98 |
{url: "https://my.fsf.org/sites/all/modules/civicrm/templates/CRM/Core/BillingBlock.js?r=lp7Di", |
|
99 |
hash:"2f25d35e7a0c0060ab0a444a577f09dd3c9934ae898a7ee0eb20b6c986ab5a1c"}, |
|
100 |
{url: "https://my.fsf.org/extensions/com.aghstrategies.giftmemberships/js/giftpricefield.js?r=lp7Di", |
|
101 |
hash:"f86080e6bd306fe46474039aeca2808235005bce5a2a29416d08210022039a45"}, |
|
102 |
{url: "https://my.fsf.org/extensions/com.ginkgostreet.negativenegator/js/negativenegator.js?r=lp7Di", |
|
103 |
hash:"d0e87bac832856db70947d82a7ab4e0b7c8b1070d5f1a32335345e033ece3a14"} |
|
104 |
]) { |
|
105 |
let name_regex = /\/([^/]+)\.js/; |
|
106 |
let name = name_regex.exec(script_data.url)[1]; |
|
107 |
await storage.set(TYPE_PREFIX.SCRIPT, name, script_data); |
|
108 |
components.push([TYPE_PREFIX.SCRIPT, name]); |
|
109 |
} |
|
110 |
|
|
111 |
await storage.set(TYPE_PREFIX.BAG, "myfsf_join", components); |
|
112 |
|
|
113 |
await storage.set(TYPE_PREFIX.PAGE, "https://my.fsf.org/join", { |
|
114 |
components: [TYPE_PREFIX.BAG, "myfsf_join"] |
|
115 |
}); |
|
116 |
|
|
117 |
let hello_script = { |
|
118 |
text: "console.log(\"hello, every1!\");\n" |
|
119 |
}; |
|
120 |
await storage.set(TYPE_PREFIX.SCRIPT, "hello", hello_script); |
|
121 |
await storage.set(TYPE_PREFIX.BAG, "hello", |
|
122 |
[[TYPE_PREFIX.SCRIPT, "hello"]]); |
|
123 |
await storage.set(TYPE_PREFIX.PAGE, "https://my.fsf.org/", { |
|
124 |
components: [TYPE_PREFIX.BAG, "hello"], |
|
125 |
allow: true |
|
126 |
}); |
|
127 |
|
|
128 |
let opencores_script = { |
|
129 |
text: `\ |
|
129 | 130 |
let data = JSON.parse(document.getElementById("__NEXT_DATA__").textContent); |
130 | 131 |
let sections = {}; |
131 | 132 |
for (let h1 of document.getElementsByClassName("cMJCrc")) { |
... | ... | |
154 | 155 |
ul.appendChild(li); |
155 | 156 |
} |
156 | 157 |
` |
157 |
};
|
|
158 |
};
|
|
158 | 159 |
|
159 |
await storage.set(TYPE_PREFIX.SCRIPT, "opencores", opencores_script);
|
|
160 |
await storage.set(TYPE_PREFIX.PAGE, "https://opencores.org/projects", {
|
|
161 |
components: [TYPE_PREFIX.SCRIPT, "opencores"],
|
|
162 |
allow: false
|
|
163 |
});
|
|
164 |
}
|
|
160 |
await storage.set(TYPE_PREFIX.SCRIPT, "opencores", opencores_script);
|
|
161 |
await storage.set(TYPE_PREFIX.PAGE, "https://opencores.org/projects", {
|
|
162 |
components: [TYPE_PREFIX.SCRIPT, "opencores"], |
|
163 |
allow: false |
|
164 |
});
|
|
165 |
} |
|
165 | 166 |
|
166 |
browser.runtime.onInstalled.addListener(init_myext);
|
|
167 |
browser.runtime.onInstalled.addListener(init_myext); |
|
167 | 168 |
|
168 |
console.log("hello, myext"); |
|
169 |
})(); |
|
169 |
console.log("hello, myext"); |
Also available in: Unified diff
emply an sh-based build system; make some changes to blocking