Revision 7c44b46e
Added by Wojtek Kosior about 2 years ago
| background/policy_smuggler.js | ||
|---|---|---|
| 1 |
/** |
|
| 2 |
* Myext smuggling policy to content script through url |
|
| 3 |
* |
|
| 4 |
* Copyright (C) 2021 Wojtek Kosior |
|
| 5 |
* |
|
| 6 |
* This code is dual-licensed under: |
|
| 7 |
* - Asshole license 1.0, |
|
| 8 |
* - GPLv3 or (at your option) any later version |
|
| 9 |
* |
|
| 10 |
* "dual-licensed" means you can choose the license you prefer. |
|
| 11 |
* |
|
| 12 |
* This code is released under a permissive license because I disapprove of |
|
| 13 |
* copyright and wouldn't be willing to sue a violator. Despite not putting |
|
| 14 |
* this code under copyleft (which is also kind of copyright), I do not want |
|
| 15 |
* it to be made proprietary. Hence, the permissive alternative to GPL is the |
|
| 16 |
* Asshole license 1.0 that allows me to call you an asshole if you use it. |
|
| 17 |
* This means you're legally ok regardless of how you utilize this code but if |
|
| 18 |
* you make it into something nonfree, you're an asshole. |
|
| 19 |
* |
|
| 20 |
* You should have received a copy of both GPLv3 and Asshole license 1.0 |
|
| 21 |
* together with this code. If not, please see: |
|
| 22 |
* - https://www.gnu.org/licenses/gpl-3.0.en.html |
|
| 23 |
* - https://koszko.org/asshole-license.txt |
|
| 24 |
*/ |
|
| 25 |
|
|
| 26 |
"use strict"; |
|
| 27 |
|
|
| 28 |
(() => {
|
|
| 29 |
const TYPE_PREFIX = window.TYPE_PREFIX; |
|
| 30 |
const get_storage = window.get_storage; |
|
| 31 |
const browser = window.browser; |
|
| 32 |
const url_item = window.url_item; |
|
| 33 |
const gen_unique = window.gen_unique; |
|
| 34 |
const get_query_best = window.get_query_best; |
|
| 35 |
|
|
| 36 |
var storage; |
|
| 37 |
var query_best; |
|
| 38 |
|
|
| 39 |
function redirect(request) |
|
| 40 |
{
|
|
| 41 |
let url_re = /^([^#]*)((#[^#]*)(#.*)?)?$/; |
|
| 42 |
let match = url_re.exec(request.url); |
|
| 43 |
let base_url = match[1]; |
|
| 44 |
let first_target = match[3]; |
|
| 45 |
let second_target = match[4]; |
|
| 46 |
|
|
| 47 |
let url = url_item(request.url); |
|
| 48 |
let unique = gen_unique(url); |
|
| 49 |
|
|
| 50 |
if (first_target === unique) {
|
|
| 51 |
console.log(["not redirecting"]); |
|
| 52 |
return {cancel : false};
|
|
| 53 |
} |
|
| 54 |
|
|
| 55 |
let [pattern, settings] = query_best(url); |
|
| 56 |
if (settings === undefined || !settings.allow) |
|
| 57 |
return {cancel : false};
|
|
| 58 |
|
|
| 59 |
second_target = (first_target || "") + (second_target || ""); |
|
| 60 |
|
|
| 61 |
console.log(["redirecting", request.url, |
|
| 62 |
(base_url + unique + second_target)]); |
|
| 63 |
|
|
| 64 |
return {
|
|
| 65 |
redirectUrl : (base_url + unique + second_target) |
|
| 66 |
}; |
|
| 67 |
} |
|
| 68 |
|
|
| 69 |
async function start() {
|
|
| 70 |
storage = await get_storage(); |
|
| 71 |
query_best = await get_query_best(); |
|
| 72 |
|
|
| 73 |
chrome.webRequest.onBeforeRequest.addListener( |
|
| 74 |
redirect, |
|
| 75 |
{
|
|
| 76 |
urls: ["<all_urls>"], |
|
| 77 |
types: ["main_frame", "sub_frame"] |
|
| 78 |
}, |
|
| 79 |
["blocking"] |
|
| 80 |
); |
|
| 81 |
} |
|
| 82 |
|
|
| 83 |
window.start_policy_smuggler = start; |
|
| 84 |
})(); |
|
| background/reverse_use_info.js | ||
|---|---|---|
| 1 |
/** |
|
| 2 |
* Myext scripts and bags usage index |
|
| 3 |
* |
|
| 4 |
* Copyright (C) 2021 Wojtek Kosior |
|
| 5 |
* |
|
| 6 |
* This code is dual-licensed under: |
|
| 7 |
* - Asshole license 1.0, |
|
| 8 |
* - GPLv3 or (at your option) any later version |
|
| 9 |
* |
|
| 10 |
* "dual-licensed" means you can choose the license you prefer. |
|
| 11 |
* |
|
| 12 |
* This code is released under a permissive license because I disapprove of |
|
| 13 |
* copyright and wouldn't be willing to sue a violator. Despite not putting |
|
| 14 |
* this code under copyleft (which is also kind of copyright), I do not want |
|
| 15 |
* it to be made proprietary. Hence, the permissive alternative to GPL is the |
|
| 16 |
* Asshole license 1.0 that allows me to call you an asshole if you use it. |
|
| 17 |
* This means you're legally ok regardless of how you utilize this code but if |
|
| 18 |
* you make it into something nonfree, you're an asshole. |
|
| 19 |
* |
|
| 20 |
* You should have received a copy of both GPLv3 and Asshole license 1.0 |
|
| 21 |
* together with this code. If not, please see: |
|
| 22 |
* - https://www.gnu.org/licenses/gpl-3.0.en.html |
|
| 23 |
* - https://koszko.org/asshole-license.txt |
|
| 24 |
*/ |
|
| 25 |
|
|
| 26 |
"use strict"; |
|
| 27 |
|
|
| 28 |
/* |
|
| 29 |
* Warning! |
|
| 30 |
* This script file has not been used for some time and underlying storage |
|
| 31 |
* model has changed since then! Fix required! |
|
| 32 |
*/ |
|
| 33 |
|
|
| 34 |
/* |
|
| 35 |
* We want to count referenes to scripts and bags in order to know, |
|
| 36 |
* for example, whether one can be safely deleted. |
|
| 37 |
*/ |
|
| 38 |
|
|
| 39 |
(() => {
|
|
| 40 |
const TYPE_PREFIX = window.TYPE_PREFIX; |
|
| 41 |
const get_storage = window.get_storage; |
|
| 42 |
const make_once = window.make_once; |
|
| 43 |
|
|
| 44 |
var component_uses = new Map(); |
|
| 45 |
var storage; |
|
| 46 |
|
|
| 47 |
function add_use_info_by_item(prefix, item, components) |
|
| 48 |
{
|
|
| 49 |
for (let component of components) {
|
|
| 50 |
component = component.join("");
|
|
| 51 |
|
|
| 52 |
let used_by_info = component_uses.get(component); |
|
| 53 |
|
|
| 54 |
if (used_by_info === undefined) {
|
|
| 55 |
used_by_info = {};
|
|
| 56 |
component_uses.set(component, used_by_info); |
|
| 57 |
} |
|
| 58 |
|
|
| 59 |
if (used_by_info[prefix] === undefined) |
|
| 60 |
used_by_info[prefix] = new Set(); |
|
| 61 |
|
|
| 62 |
used_by_info[prefix].add(item); |
|
| 63 |
} |
|
| 64 |
} |
|
| 65 |
|
|
| 66 |
function remove_use_info_by_item(prefix, item, components) |
|
| 67 |
{
|
|
| 68 |
for (let component of components) {
|
|
| 69 |
used_by_info = component_uses.get(component.join(""));
|
|
| 70 |
if (used_by_info === undefined || |
|
| 71 |
used_by_info[prefix] === undefined) |
|
| 72 |
return; |
|
| 73 |
|
|
| 74 |
used_by_info[prefix].delete(item); |
|
| 75 |
} |
|
| 76 |
} |
|
| 77 |
|
|
| 78 |
function build_reverse_uses_info(entries_it, type_prefix) |
|
| 79 |
{
|
|
| 80 |
for (let [item, components] of storage.get_all_it(type_prefix)) |
|
| 81 |
add_use_info_by_item(type_prefix, item, components); |
|
| 82 |
} |
|
| 83 |
|
|
| 84 |
function handle_change(change) |
|
| 85 |
{
|
|
| 86 |
if (change.old_val !== undefined) |
|
| 87 |
remove_use_info_by_item(change.prefix, change.item, change.old_val); |
|
| 88 |
|
|
| 89 |
if (change.new_val !== undefined) |
|
| 90 |
add_use_info_by_item(change.prefix, change.item, change.new_val); |
|
| 91 |
} |
|
| 92 |
|
|
| 93 |
function get_uses(arg1, arg2=undefined) |
|
| 94 |
{
|
|
| 95 |
let [prefix, item] = [arg1, arg2]; |
|
| 96 |
|
|
| 97 |
if (arg2 === undefined) |
|
| 98 |
[prefix, item] = arg1; |
|
| 99 |
|
|
| 100 |
return component_uses.get(prefix + item); |
|
| 101 |
} |
|
| 102 |
|
|
| 103 |
async function init() |
|
| 104 |
{
|
|
| 105 |
storage = await get_storage(); |
|
| 106 |
|
|
| 107 |
prefixes = [TYPE_PREFIX.PAGE, TYPE_PREFIX.BAG]; |
|
| 108 |
for (let prefix of prefixes) |
|
| 109 |
build_reverse_uses_info(prefix); |
|
| 110 |
|
|
| 111 |
storage.add_change_listener(handle_change, prefixes); |
|
| 112 |
|
|
| 113 |
return get_uses; |
|
| 114 |
} |
|
| 115 |
|
|
| 116 |
window.get_reverse_use_info = make_once(init); |
|
| 117 |
})(); |
|
Also available in: Unified diff
remove unused source files