Skip to content

Commit

Permalink
Closes #768
Browse files Browse the repository at this point in the history
Closes #766
Closes #765
Fix settings page opening in more than one tab
  • Loading branch information
ParticleCore committed Oct 15, 2019
1 parent dc79b9c commit e938f14
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 26 deletions.
2 changes: 1 addition & 1 deletion bin/update.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"[email protected]" : {
"updates" : [
{
"version" : "1.2.0",
"version" : "1.2.1",
"update_link" : "https://github.com/ParticleCore/Iridium/raw/master/dist/Iridium.xpi",
"applications" : {
"gecko" : {
Expand Down
Binary file modified dist/Iridium.xpi
Binary file not shown.
85 changes: 68 additions & 17 deletions src/js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,6 @@ api = {
return {};
}

if (settings.autoPlayVideo &&
!settings.maxResThumbnail
) {
return;
}

let modifier;

modifier = function (str) {
Expand Down Expand Up @@ -136,21 +130,18 @@ api = {
/(\.onDone=function\(([a-z0-9]+)\){)/gi,
"$1(" + window.pbjMod + "($2));"
)
;

str = str
.replace(
/(updatePageData_:function\(([a-z0-9]+)\){)/gi,
"$1(window.pageModifier($2));"
)
.replace(
/([a-z0-9.]+)loadVideoByPlayerVars\(([^)]+)\)/gi,
"(window.autoPlayVideo!==false?$1loadVideoByPlayerVars($2):$1cueVideoByPlayerVars($2))"
)
;

if (!settings.autoPlayVideo) {
str = str
.replace(
/([a-z0-9.]+)loadVideoByPlayerVars\(([^)]+)\)/gi,
"(window.autoPlayVideo!==false?$1loadVideoByPlayerVars($2):$1cueVideoByPlayerVars($2))"
)
.replace(
/config_\.loaded=!0/g,
"config_.loaded=!1"
Expand Down Expand Up @@ -196,6 +187,20 @@ api = {
}

function updateCookie(cookie) {

if (cookie === null) {
cookie = {
name: "PREF",
value: "f6=400",
domain: ".youtube.com",
path: "/",
secure: false,
httpOnly: false,
sameSite: "no_restriction",
expirationDate: Math.round(Date.now() / 1000)
};
}

chrome.cookies.set({
url: YT_DOMAIN,
name: cookie.name,
Expand All @@ -208,9 +213,9 @@ api = {
secure: cookie.secure,
httpOnly: cookie.httpOnly,
sameSite: cookie.sameSite,
expirationDate: cookie.expirationDate,
storeId: cookie.storeId
expirationDate: cookie.expirationDate
});

}

let values;
Expand Down Expand Up @@ -288,9 +293,45 @@ api = {
sender,
sendResponse
) {

if (request === GET_BROADCAST_ID) {

sendResponse(api.broadcastId);
return;

}

console.log(request);

let data;

for (let key in request) {

if (!request.hasOwnProperty(key)) {
continue;
}

data = {};

if (key in settings) {
if (request[key] !== settings[key]) {

settings[key] = request[key];
data[key] = settings[key];

}
}

if (Object.keys(data).length < 1) {
return;
}

chrome.storage.local.set(data, function (event) {
console.log("onMessageListener", event);
});

}

}

function onStorageChangedListener(
Expand All @@ -311,9 +352,19 @@ api = {
}

function onBrowserActionClickedListener() {
chrome.tabs.create({
url: chrome.runtime.getURL("html/options.html")

let url;

url = chrome.runtime.getURL("html/options.html");

chrome.tabs.query({url: url}, function (tabs) {
if (tabs.length > 0) {
chrome.tabs.update(tabs[0].id, {active: true});
} else {
chrome.tabs.create({url: url});
}
});

}

chrome.runtime.onMessage.addListener(onMessageListener);
Expand Down
4 changes: 1 addition & 3 deletions src/js/content-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ function onMessageResponse(data) {
return;
}

chrome.storage.local.set(event.data.payload, function (event) {
console.log("onMessageListener", event);
});
chrome.runtime.sendMessage(event.data.payload);

}

Expand Down
12 changes: 8 additions & 4 deletions src/js/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,16 @@ function onSettingsChanged(
) {

for (let key in changes) {
if (changes.hasOwnProperty(key)) {

settings[key] = changes[key].newValue;
updateSetting(key, settings[key]);

if (!changes.hasOwnProperty(key) ||
changes[key].newValue === changes[key].oldValue
) {
continue;
}

settings[key] = changes[key].newValue;
updateSetting(key, settings[key]);

}
}

Expand Down
3 changes: 2 additions & 1 deletion src/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifest_version": 2,
"name": "Iridium for YouTube",
"version": "1.2.0",
"version": "1.2.1",
"description": "YouTube with more freedom",
"default_locale": "en_US",
"icons": {
Expand Down Expand Up @@ -36,6 +36,7 @@
}
],
"permissions": [
"tabs",
"storage",
"cookies",
"webRequest",
Expand Down

0 comments on commit e938f14

Please sign in to comment.