diff --git a/extension/content-script.js b/extension/content-script.js index 41739f1b..d87edd43 100644 --- a/extension/content-script.js +++ b/extension/content-script.js @@ -1,1019 +1,1068 @@ /* Copyright (C) 2017 Kai Uwe Broulik Copyright (C) 2018 David Edmundson This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ var callbacks = {}; // from https://stackoverflow.com/questions/105034/create-guid-uuid-in-javascript function generateGuid() { return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { const r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8); return v.toString(16); }); } function addCallback(subsystem, action, callback) { if (!callbacks[subsystem]) { callbacks[subsystem] = {}; } callbacks[subsystem][action] = callback; } function executeScript(script) { var element = document.createElement('script'); element.innerHTML = '('+ script +')();'; (document.body || document.head || document.documentElement).appendChild(element); // We need to remove the script tag after inserting or else websites relying on the order of items in // document.getElementsByTagName("script") will break (looking at you, Google Hangouts) element.parentNode.removeChild(element); } chrome.runtime.onMessage.addListener(function (message, sender) { // TODO do something with sender (check privilige or whatever) var subsystem = message.subsystem; var action = message.action; if (!subsystem || !action) { return; } if (callbacks[subsystem] && callbacks[subsystem][action]) { callbacks[subsystem][action](message.payload); } }); SettingsUtils.get().then((items) => { if (items.breezeScrollBars.enabled) { loadBreezeScrollBars(); } const mpris = items.mpris; if (mpris.enabled) { const origin = window.location.origin; const websiteSettings = mpris.websiteSettings || {}; let mprisAllowed = true; if (typeof MPRIS_WEBSITE_SETTINGS[origin] === "boolean") { mprisAllowed = MPRIS_WEBSITE_SETTINGS[origin]; } if (typeof websiteSettings[origin] === "boolean") { mprisAllowed = websiteSettings[origin]; } if (mprisAllowed) { loadMpris(); if (items.mprisMediaSessions.enabled) { loadMediaSessionsShim(); } } } if (items.purpose.enabled) { sendMessage("settings", "getSubsystemStatus").then((status) => { if (status && status.purpose) { loadPurpose(); } }, (err) => { // No warning, can also happen when port isn't connected for unsupported OS console.log("Failed to get subsystem status for purpose", err); }); } }); // BREEZE SCROLL BARS // ------------------------------------------------------------------------ // function loadBreezeScrollBars() { if (IS_FIREFOX) { return; } if (!document.head) { return; } // You cannot access cssRules for on a different domain. // Since our chrome-extension:// URL for a stylesheet would be, this can // lead to problems in e.g modernizr, so include the