Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bumped autochrome_junk_drawer to manifest v3 #33

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions data/extension_source/autochrome_junk_drawer/background.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
let autochrome_profile_name = null;

/*
permissions: ['declarativeNetRequestFeedback'],
chrome.declarativeNetRequest.onRuleMatchedDebug.addListener(
(info) => {
const req = info.request;
const rule = info.rule;
console.log(`[${rule.rulesetId}:${rule.ruleId}] ${req.method} ${req.url}`);
}
);
*/


const profiles = [
'blue',
'cyan',
'green',
'orange',
'purple',
'red',
'white',
'yellow'
];

async function getProfileNameFromStorage() {
if (autochrome_profile_name != null) {
return;
}

await chrome.storage.local.get("profile_name", (items) => {
const name = items["profile_name"];
// console.log(`[STORAGE] Got profile name: "${name}"`);
if (typeof name == "string") {
autochrome_profile_name = name;
}
});

if (autochrome_profile_name == null) {
await getProfileNameFromManagement();
}
}

async function getProfileNameFromManagement() {
await chrome.management.getAll((extensionInfoArray) => {
extensionInfoArray.forEach((extensionInfo) => {
if (extensionInfo.type === "theme" && extensionInfo.enabled) {
const color = extensionInfo.name.replace(/^Caution\s+(\w+)$/, '$1').toLowerCase();
if (profiles.find((c) => color === c) != undefined) {
autochrome_profile_name = color;
}
}});
}
);
// console.log(`[MANAGEMENT] Got profile name: "${autochrome_profile_name}"`);
if (autochrome_profile_name != null) {
await chrome.storage.local.set({profile_name: autochrome_profile_name});
}
}

getProfileNameFromStorage();
setTimeout(() => {
if (autochrome_profile_name != null) {
console.log(`Got profile name: ${autochrome_profile_name}`);
chrome.declarativeNetRequest.updateEnabledRulesets({
enableRulesetIds: [`ruleset_tag_${autochrome_profile_name}`]
});
} else {
console.log(`Cannot get profile name: ${autochrome_profile_name}`);
}
}, 100);
62 changes: 53 additions & 9 deletions data/extension_source/autochrome_junk_drawer/manifest.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,61 @@
{
"manifest_version": 2,
"manifest_version": 3,
"name": "Autochrome Integration",
"version": "2.0",
"description": "Kitchen sink extension for Autochrome. Includes the start page and User-Agent tagging.",
"version": "1.1",

"background": {
"scripts": ["request_handler.js"]
"service_worker": "background.js"
},
"permissions": [
"*://*/*",
"bookmarks",
"management",
"storage",
"webRequest",
"webRequestBlocking"
]
"declarativeNetRequestWithHostAccess"
],
"host_permissions": [
"*://*/*"
],
"declarative_net_request": {
"rule_resources": [
{
"id": "ruleset_tag_blue",
"enabled": false,
"path": "useragent_tag_blue.json"
},
{
"id": "ruleset_tag_cyan",
"enabled": false,
"path": "useragent_tag_cyan.json"
},
{
"id": "ruleset_tag_green",
"enabled": false,
"path": "useragent_tag_green.json"
},
{
"id": "ruleset_tag_orange",
"enabled": false,
"path": "useragent_tag_orange.json"
},
{
"id": "ruleset_tag_purple",
"enabled": false,
"path": "useragent_tag_purple.json"
},
{
"id": "ruleset_tag_red",
"enabled": false,
"path": "useragent_tag_red.json"
},
{
"id": "ruleset_tag_white",
"enabled": false,
"path": "useragent_tag_white.json"
},
{
"id": "ruleset_tag_yellow",
"enabled": false,
"path": "useragent_tag_yellow.json"
}
]
}
}
67 changes: 0 additions & 67 deletions data/extension_source/autochrome_junk_drawer/request_handler.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
[
{
"id": 1,
"action": {
"type": "modifyHeaders",
"requestHeaders": [
{
"header": "X-Autochrome-Tag",
"operation": "set",
"value": "blue"
}
]
},
"condition": {
"urlFilter": "*",
"resourceTypes": [
"main_frame",
"sub_frame",
"stylesheet",
"script",
"image",
"font",
"object",
"xmlhttprequest",
"ping",
"csp_report",
"media",
"websocket",
"webtransport",
"webbundle",
"other"
]
}
},
{
"id": 2,
"action": {
"type": "modifyHeaders",
"requestHeaders": [
{
"header": "User-Agent",
"operation": "set",
"value": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36 autochrome/blue"
}
]
},
"condition": {
"urlFilter": "*",
"resourceTypes": [
"main_frame",
"sub_frame",
"stylesheet",
"script",
"image",
"font",
"object",
"xmlhttprequest",
"ping",
"csp_report",
"media",
"websocket",
"webtransport",
"webbundle",
"other"
]
}
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
[
{
"id": 1,
"action": {
"type": "modifyHeaders",
"requestHeaders": [
{
"header": "X-Autochrome-Tag",
"operation": "set",
"value": "cyan"
}
]
},
"condition": {
"urlFilter": "*",
"resourceTypes": [
"main_frame",
"sub_frame",
"stylesheet",
"script",
"image",
"font",
"object",
"xmlhttprequest",
"ping",
"csp_report",
"media",
"websocket",
"webtransport",
"webbundle",
"other"
]
}
},
{
"id": 2,
"action": {
"type": "modifyHeaders",
"requestHeaders": [
{
"header": "User-Agent",
"operation": "set",
"value": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36 autochrome/cyan"
}
]
},
"condition": {
"urlFilter": "*",
"resourceTypes": [
"main_frame",
"sub_frame",
"stylesheet",
"script",
"image",
"font",
"object",
"xmlhttprequest",
"ping",
"csp_report",
"media",
"websocket",
"webtransport",
"webbundle",
"other"
]
}
}
]
Loading