mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2026-01-01 22:29:20 +03:00
Added option to enable invidious support.
This commit is contained in:
@@ -344,5 +344,11 @@
|
||||
},
|
||||
"keybindCurrentlySet": {
|
||||
"message": ". It is currently set to:"
|
||||
},
|
||||
"supportInvidious": {
|
||||
"message": "Support Invidious"
|
||||
},
|
||||
"supportInvidiousDescription": {
|
||||
"message": "Invidious (invidio.us) is a third party YouTube client. To enable support, you must accept the extra permissions."
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,9 +8,7 @@
|
||||
{
|
||||
"matches": [
|
||||
"https://*.youtube.com/*",
|
||||
"https://www.youtube-nocookie.com/embed/*",
|
||||
"https://*.invidio.us/*",
|
||||
"https://*.invidiou.sh/*"
|
||||
"https://www.youtube-nocookie.com/embed/*"
|
||||
],
|
||||
"all_frames": true,
|
||||
"js": [
|
||||
@@ -46,7 +44,12 @@
|
||||
"permissions": [
|
||||
"storage",
|
||||
"notifications",
|
||||
"https://sponsor.ajay.app/*"
|
||||
"https://sponsor.ajay.app/*",
|
||||
"https://*.invidio.us/*"
|
||||
],
|
||||
"optional_permissions": [
|
||||
"declarativeContent",
|
||||
"https://*/*"
|
||||
],
|
||||
"browser_action": {
|
||||
"default_title": "__MSG_Name__",
|
||||
|
||||
@@ -21,6 +21,22 @@
|
||||
|
||||
<div id="options" class="hidden">
|
||||
|
||||
<div option-type="toggle" sync-option="supportInvidious">
|
||||
<label class="switch-container" label-name="__MSG_supportInvidious__">
|
||||
<label class="switch">
|
||||
<input type="checkbox">
|
||||
<span class="slider round"></span>
|
||||
</label>
|
||||
</label>
|
||||
|
||||
<br/>
|
||||
<br/>
|
||||
|
||||
<div class="small-description">__MSG_supportInvidiousDescription__</div>
|
||||
</div>
|
||||
|
||||
<br/>
|
||||
<br/>
|
||||
|
||||
<div option-type="toggle" toggle-type="reverse" sync-option="disableAutoSkip">
|
||||
<label class="switch-container" label-name="__MSG_autoSkip__">
|
||||
|
||||
@@ -16,21 +16,76 @@ async function init() {
|
||||
let option = optionsElements[i].getAttribute("sync-option");
|
||||
chrome.storage.sync.get([option], function(result) {
|
||||
let optionResult = result[option];
|
||||
if (optionResult != undefined) {
|
||||
let checkbox = optionsElements[i].querySelector("input");
|
||||
checkbox.checked = optionResult;
|
||||
|
||||
let reverse = optionsElements[i].getAttribute("toggle-type") === "reverse";
|
||||
|
||||
if (optionResult != undefined) {
|
||||
checkbox.checked = optionResult;
|
||||
|
||||
if (reverse) {
|
||||
optionsElements[i].querySelector("input").checked = !optionResult;
|
||||
}
|
||||
}
|
||||
|
||||
checkbox.addEventListener("click", () =>{
|
||||
setOptionValue(option, reverse ? !checkbox.checked : checkbox.checked)
|
||||
setOptionValue(option, reverse ? !checkbox.checked : checkbox.checked);
|
||||
// See if anything extra must be run
|
||||
switch (option) {
|
||||
case "supportInvidious":
|
||||
if (checkbox.checked) {
|
||||
// Request permission
|
||||
chrome.permissions.request({
|
||||
origins: ["https://*.invidio.us/*"],
|
||||
permissions: ["declarativeContent"]
|
||||
}, function (granted) {
|
||||
if (granted) {
|
||||
chrome.declarativeContent.onPageChanged.removeRules(["invidious"], function() {
|
||||
// Add page rule
|
||||
let rule = {
|
||||
id: "invidious",
|
||||
conditions: [
|
||||
new chrome.declarativeContent.PageStateMatcher({
|
||||
pageUrl: { urlMatches: "https://*.invidio.us/*" }
|
||||
})
|
||||
],
|
||||
actions: [new chrome.declarativeContent.RequestContentScript({
|
||||
allFrames: true,
|
||||
js: [
|
||||
"config.js",
|
||||
"utils/previewBar.js",
|
||||
"utils/skipNotice.js",
|
||||
"utils.js",
|
||||
"content.js",
|
||||
"popup.js"
|
||||
],
|
||||
css: [
|
||||
"content.css",
|
||||
"./libs/Source+Sans+Pro.css",
|
||||
"popup.css"
|
||||
]
|
||||
})]
|
||||
};
|
||||
|
||||
chrome.declarativeContent.onPageChanged.addRules([rule], console.log);
|
||||
});
|
||||
} else {
|
||||
setOptionValue(option, false);
|
||||
checkbox.checked = false;
|
||||
|
||||
chrome.declarativeContent.onPageChanged.removeRules(["invidious"]);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
chrome.declarativeContent.onPageChanged.removeRules(["invidious"]);
|
||||
chrome.permissions.remove({
|
||||
origins: ["https://*.invidio.us/*"]
|
||||
});
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
checksLeft--;
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user