Chrome is fucking cancer and its sendMessage() (both in chrome.tabs as well as chrome.runtime) sucks major ass.

This commit is contained in:
Tamius Han 2018-01-08 22:48:45 +01:00
parent 88bbf1cb07
commit 45c986d66d
10 changed files with 653 additions and 147 deletions

View File

@ -1,5 +1,5 @@
// Set prod to true when releasing
_prod = true;
// _prod = true;
// _prod = false;
Debug = {

View File

@ -0,0 +1,243 @@
/** Wrap an API that uses callbacks with Promises
* This expects the pattern function withCallback(arg1, arg2, ... argN, callback)
* @author Keith Henry <keith.henry@evolutionjobs.co.uk>
* @license MIT */
(function () {
'use strict';
/** Wrap a function with a callback with a Promise.
* @param {function} f The function to wrap, should be pattern: withCallback(arg1, arg2, ... argN, callback).
* @param {function} parseCB Optional function to parse multiple callback parameters into a single object.
* @returns {Promise} Promise that resolves when the callback fires. */
function promisify(f, parseCB) {
return (...args) => {
let safeArgs = args;
let callback;
// The Chrome API functions all use arguments, so we can't use f.length to check
// If there is a last arg
if (args && args.length > 0) {
// ... and the last arg is a function
const last = args[args.length - 1];
if (typeof last === 'function') {
// Trim the last callback arg if it's been passed
safeArgs = args.slice(0, args.length - 1);
callback = last;
}
}
// Return a promise
return new Promise((resolve, reject) => {
try {
// Try to run the original function, with the trimmed args list
f(...safeArgs, (...cbArgs) => {
// If a callback was passed at the end of the original arguments
if (callback) {
// Don't allow a bug in the callback to stop the promise resolving
try { callback(...cbArgs); }
catch (cbErr) { reject(cbErr); }
}
// Chrome extensions always fire the callback, but populate chrome.runtime.lastError with exception details
if (chrome.runtime.lastError)
// Return as an error for the awaited catch block
reject(new Error(chrome.runtime.lastError.message || `Error thrown by API ${chrome.runtime.lastError}`));
else {
if (parseCB) {
const cbObj = parseCB(...cbArgs);
resolve(cbObj);
}
else if (!cbArgs || cbArgs.length === 0)
resolve();
else if (cbArgs.length === 1)
resolve(cbArgs[0]);
else
resolve(cbArgs);
}
});
}
catch (err) { reject(err); }
});
}
}
/** Promisify all the known functions in the map
* @param {object} api The Chrome native API to extend
* @param {Array} apiMap Collection of sub-API and functions to promisify */
function applyMap(api, apiMap) {
if (!api)
// Not supported by current permissions
return;
for (let funcDef of apiMap) {
let funcName;
if (typeof funcDef === 'string')
funcName = funcDef;
else {
funcName = funcDef.n;
}
if (!api.hasOwnProperty(funcName))
// Member not in API
continue;
const m = api[funcName];
if (typeof m === 'function')
// This is a function, wrap in a promise
api[funcName] = promisify(m, funcDef.cb);
else
// Sub-API, recurse this func with the mapped props
applyMap(m, funcDef.props);
}
}
/** Apply promise-maps to the Chrome native API.
* @param {object} apiMaps The API to apply. */
function applyMaps(apiMaps) {
for (let apiName in apiMaps) {
const callbackApi = chrome[apiName];
if (!callbackApi)
// Not supported by current permissions
continue;
const apiMap = apiMaps[apiName];
applyMap(callbackApi, apiMap);
}
}
// accessibilityFeatures https://developer.chrome.com/extensions/accessibilityFeatures
const knownA11ySetting = ['get', 'set', 'clear'];
// ContentSetting https://developer.chrome.com/extensions/contentSettings#type-ContentSetting
const knownInContentSetting = ['clear', 'get', 'set', 'getResourceIdentifiers'];
// StorageArea https://developer.chrome.com/extensions/storage#type-StorageArea
const knownInStorageArea = ['get', 'getBytesInUse', 'set', 'remove', 'clear'];
/** Map of API functions that follow the callback pattern that we can 'promisify' */
applyMaps({
accessibilityFeatures: [ // Todo: this should extend AccessibilityFeaturesSetting.prototype instead
{ n: 'spokenFeedback', props: knownA11ySetting },
{ n: 'largeCursor', props: knownA11ySetting },
{ n: 'stickyKeys', props: knownA11ySetting },
{ n: 'highContrast', props: knownA11ySetting },
{ n: 'screenMagnifier', props: knownA11ySetting },
{ n: 'autoclick', props: knownA11ySetting },
{ n: 'virtualKeyboard', props: knownA11ySetting },
{ n: 'animationPolicy', props: knownA11ySetting }],
alarms: ['get', 'getAll', 'clear', 'clearAll'],
bookmarks: [
'get', 'getChildren', 'getRecent', 'getTree', 'getSubTree',
'search', 'create', 'move', 'update', 'remove', 'removeTree'],
browser: ['openTab'],
browserAction: [
'getTitle', 'setIcon', 'getPopup', 'getBadgeText', 'getBadgeBackgroundColor'],
browsingData: [
'settings', 'remove', 'removeAppcache', 'removeCache',
'removeCookies', 'removeDownloads', 'removeFileSystems',
'removeFormData', 'removeHistory', 'removeIndexedDB',
'removeLocalStorage', 'removePluginData', 'removePasswords',
'removeWebSQL'],
commands: ['getAll'],
contentSettings: [ // Todo: this should extend ContentSetting.prototype instead
{ n: 'cookies', props: knownInContentSetting },
{ n: 'images', props: knownInContentSetting },
{ n: 'javascript', props: knownInContentSetting },
{ n: 'location', props: knownInContentSetting },
{ n: 'plugins', props: knownInContentSetting },
{ n: 'popups', props: knownInContentSetting },
{ n: 'notifications', props: knownInContentSetting },
{ n: 'fullscreen', props: knownInContentSetting },
{ n: 'mouselock', props: knownInContentSetting },
{ n: 'microphone', props: knownInContentSetting },
{ n: 'camera', props: knownInContentSetting },
{ n: 'unsandboxedPlugins', props: knownInContentSetting },
{ n: 'automaticDownloads', props: knownInContentSetting }],
contextMenus: ['create', 'update', 'remove', 'removeAll'],
cookies: ['get', 'getAll', 'set', 'remove', 'getAllCookieStores'],
debugger: ['attach', 'detach', 'sendCommand', 'getTargets'],
desktopCapture: ['chooseDesktopMedia'],
// TODO: devtools.*
documentScan: ['scan'],
downloads: [
'download', 'search', 'pause', 'resume', 'cancel',
'getFileIcon', 'erase', 'removeFile', 'acceptDanger'],
enterprise: [{ n: 'platformKeys', props: ['getToken', 'getCertificates', 'importCertificate', 'removeCertificate'] }],
extension: ['isAllowedIncognitoAccess', 'isAllowedFileSchemeAccess'], // mostly deprecated in favour of runtime
fileBrowserHandler: ['selectFile'],
fileSystemProvider: ['mount', 'unmount', 'getAll', 'get', 'notify'],
fontSettings: [
'setDefaultFontSize', 'getFont', 'getDefaultFontSize', 'getMinimumFontSize',
'setMinimumFontSize', 'getDefaultFixedFontSize', 'clearDefaultFontSize',
'setDefaultFixedFontSize', 'clearFont', 'setFont', 'clearMinimumFontSize',
'getFontList', 'clearDefaultFixedFontSize'],
gcm: ['register', 'unregister', 'send'],
history: ['search', 'getVisits', 'addUrl', 'deleteUrl', 'deleteRange', 'deleteAll'],
i18n: ['getAcceptLanguages', 'detectLanguage'],
identity: [
'getAuthToken', 'getProfileUserInfo', 'removeCachedAuthToken',
'launchWebAuthFlow', 'getRedirectURL'],
idle: ['queryState'],
input: [{
n: 'ime', props: [
'setMenuItems', 'commitText', 'setCandidates', 'setComposition', 'updateMenuItems',
'setCandidateWindowProperties', 'clearComposition', 'setCursorPosition', 'sendKeyEvents',
'deleteSurroundingText']
}],
management: [
'setEnabled', 'getPermissionWarningsById', 'get', 'getAll',
'getPermissionWarningsByManifest', 'launchApp', 'uninstall', 'getSelf',
'uninstallSelf', 'createAppShortcut', 'setLaunchType', 'generateAppForLink'],
networking: [{ n: 'config', props: ['setNetworkFilter', 'finishAuthentication'] }],
notifications: ['create', 'update', 'clear', 'getAll', 'getPermissionLevel'],
pageAction: ['getTitle', 'setIcon', 'getPopup'],
pageCapture: ['saveAsMHTML'],
permissions: ['getAll', 'contains', 'request', 'remove'],
platformKeys: ['selectClientCertificates', 'verifyTLSServerCertificate',
{ n: "getKeyPair", cb: (publicKey, privateKey) => { return { publicKey, privateKey }; } }],
runtime: [
'getBackgroundPage', 'openOptionsPage', 'setUninstallURL',
'restartAfterDelay', 'sendMessage',
'sendNativeMessage', 'getPlatformInfo', 'getPackageDirectoryEntry',
{ n: "requestUpdateCheck", cb: (status, details) => { return { status, details }; } }],
scriptBadge: ['getPopup'],
sessions: ['getRecentlyClosed', 'getDevices', 'restore'],
storage: [ // Todo: this should extend StorageArea.prototype instead
{ n: 'sync', props: knownInStorageArea },
{ n: 'local', props: knownInStorageArea },
{ n: 'managed', props: knownInStorageArea }],
socket: [
'create', 'connect', 'bind', 'read', 'write', 'recvFrom', 'sendTo',
'listen', 'accept', 'setKeepAlive', 'setNoDelay', 'getInfo', 'getNetworkList'],
sockets: [
{ n: 'tcp', props: [
'create','update','setPaused','setKeepAlive','setNoDelay','connect',
'disconnect','secure','send','close','getInfo','getSockets'] },
{ n: 'tcpServer', props: [
'create','update','setPaused','listen','disconnect','close','getInfo','getSockets'] },
{ n: 'udp', props: [
'create','update','setPaused','bind','send','close','getInfo',
'getSockets','joinGroup','leaveGroup','setMulticastTimeToLive',
'setMulticastLoopbackMode','getJoinedGroups','setBroadcast'] }],
system: [
{ n: 'cpu', props: ['getInfo'] },
{ n: 'memory', props: ['getInfo'] },
{ n: 'storage', props: ['getInfo', 'ejectDevice', 'getAvailableCapacity'] }],
tabCapture: ['capture', 'getCapturedTabs'],
tabs: [
'get', 'getCurrent', 'sendMessage', 'create', 'duplicate',
'query', 'highlight', 'update', 'move', 'reload', 'remove',
'detectLanguage', 'captureVisibleTab', 'executeScript',
'insertCSS', 'setZoom', 'getZoom', 'setZoomSettings',
'getZoomSettings', 'discard'],
topSites: ['get'],
tts: ['isSpeaking', 'getVoices', 'speak'],
types: ['set', 'get', 'clear'],
vpnProvider: ['createConfig', 'destroyConfig', 'setParameters', 'sendPacket', 'notifyConnectionStateChanged'],
wallpaper: ['setWallpaper'],
webNavigation: ['getFrame', 'getAllFrames', 'handlerBehaviorChanged'],
windows: ['get', 'getCurrent', 'getLastFocused', 'getAll', 'create', 'update', 'remove']
});
})();

311
js/lib/ChromeCancer.js Normal file
View File

@ -0,0 +1,311 @@
// Chrome's tabs.sendMessage() and runtime.sendMessage() APIs are pure cancer
// attempts to make those two work like their Firefox counterparts have failed
//
// because Chrome's implementation of tabs.sendMessage() and runtime.sendMessage()
// make code less nice and more prone to turn into spaghetti _all_ chrome functions
// dealing with these have been moved to this file. Don't forget to include in manifest.
//
//
// welcome to callback hell
var _cancer_hasVideos_lastValue = undefined;
var _cancer_arActive_lastValue = undefined;
async function _cancer_recvmsg(message, sender, sendResponse){
if(Debug.debug){
console.log("[ChromeCancer::_cancer_recvmsg] received message", message);
}
var tabs = await Comms.queryTabs({currentWindow: true, active: true});
message.sender = "uwbg";
message.receiver = "uw";
if(message.cmd == "has-videos"){
if(tabs.length == 0)
return false;
chrome.tabs.sendMessage(tabs[0].id, message, /*options,*/ function(response){
if(Debug.debug)
console.log("[ChromeCancer::_cancer_recvmsg] received response for -- has-videos -- ", response);
var resp = {response: response};
if(Debug.debug)
console.log("[ChromeCancer::_cancer_recvmsg] sending response for -- has-videos -- ", response);
_cancer_hasVideos_lastValue = response.response;
sendResponse(resp);
});
}
if(message.cmd == "has-videos-cancer"){
var resp = {response: _cancer_hasVideos_lastValue};
sendResponse(resp);
}
if(message.cmd == "get-config-cancer"){
var resp = _cancer_arActive_lastValue;
sendResponse(resp);
}
if(message.cmd == "get-config"){
if (tabs.length == 0)
return false;
message.cmd = "get-ardetect-active";
var config = {};
config.videoAlignment = Settings.miscFullscreenSettings.videoFloat;
config.arConf = {};
config.arConf.enabled_global = Settings.arDetect.enabled == "global";
var keybinds = await Keybinds.fetch();
if(Debug.debug)
console.log("[ChromeCancer::_cancer_recvmsg] Keybinds.fetch returned this:", keybinds);
config.keyboardShortcuts = keybinds;
// predvidevajmo, da je enako. Če je drugače, bomo popravili ko dobimo odgovor
// assume current is same as global & change that when you get response from content script
config.arConf.enabled_current = Settings.arDetect.enabled == "global";
chrome.tabs.sendMessage(tabs[0].id, message, /*options,*/ function(response){
if(Debug.debug){
console.log("[ChromeCancer::_cancer_recvmsg] (callback) config so far:", config);
}
if(response !== undefined){
config.arConf.enabled_current = response.response.arDetect_active;
}
else if(Debug.debug){
console.log("[ChromeCancer::_cancer_recvmsg] (callback) response undefined:", response);
}
var resp = {response: config};
if(Debug.debug)
console.log("[ChromeCancer::_cancer_recvmsg] sending response for -- get-config --", resp);
_cancer_aractive_lastValue = resp;
sendResponse(resp);
});
}
else if(message.cmd == "force-ar"){
if (tabs.length == 0)
return false;
chrome.tabs.sendMessage(tabs[0].id, message); // args: {cmd: string, newAr: number/"auto"}
}
else if(message.cmd == "stop-autoar"){
if (tabs.length == 0)
return false;
chrome.tabs.sendMessage(tabs[0].id, message);
}
else if(message.cmd == "force-video-float"){
if (tabs.length == 0)
return false;
if(message.global){
Settings.miscFullscreenSettings.videoFloat = message.newFloat;
}
chrome.tabs.sendMessage(tabs[0].id, message);
}
else if(message.cmd == "disable-autoar"){
Settings.arDetect.enabled = "no";
Settings.save();
if (tabs.length == 0)
return false;
chrome.tabs.sendMessage(tabs[0].id, "reload-settings");
}
else if(message.cmd == "disable-autoar-whitelist-only"){
Settings.arDetect.enabled = "whitelist";
Settings.save();
if (tabs.length == 0)
return false;
chrome.tabs.sendMessage(tabs[0].id, "reload-settings");
}
else if(message.cmd == "enable-autoar"){
Settings.arDetect.enabled = "global";
Settings.save();
if (tabs.length == 0)
return false;
chrome.tabs.sendMessage(tabs[0].id, "reload-settings");
}
}
function _cancer_content_receiveMessage(message, sender, sendResponse){
if(Debug.debug)
console.log("[ChromeCancer::receiveMessage_cs] ] we received a message.", message);
if(message.cmd == "has-videos"){
var anyVideos = PageInfo.hasVideos();
var resp = {response: {"hasVideos": anyVideos }};
if(Debug.debug)
console.log("[ChromeCancer::receiveMessage_cs] ] sending response for has-videos:",resp);
sendResponse(resp);
}
else if(message.cmd == "get-ardetect-active"){
var arDetect_active = ArDetect.isRunning();
var resp = {response: {"arDetect_active": arDetect_active }}
if(Debug.debug)
console.log("[ChromeCancer::receiveMessage_cs] ] sending response for get-ardetect-active:",resp);
sendResponse(resp);
}
else if(message.cmd == "force-ar"){
if(Debug.debug)
console.log("[ChromeCancer::receiveMessage_cs] ] we're being commanded to change aspect ratio to", message.newAr);
if(message.newAr == "auto"){
ArDetect.stop(); // just in case
ArDetect.arSetup();
}
else{
ArDetect.stop();
// we aren't in full screen, but we will want aspect ratio to be fixed when we go to
Resizer.setFsAr(message.newAr);
}
}
else if(message.cmd == "force-video-float"){
if(Debug.debug)
console.log("[ChromeCancer::receiveMessage_cs] ] we're aligning video to", message.newFloat);
Settings.miscFullscreenSettings.videoFloat = message.newFloat;
Settings.save();
}
else if(message.cmd == "stop-autoar"){
ArDetect.stop();
}
else if(message.cmd == "reload-settings"){
Settings.reload();
}
}
function _cancer_check4conf(){
var command = {};
command.cmd = "get-config";
command.sender = "popup";
command.receiver = "uwbg";
browser.runtime.sendMessage(command, function(response){
if(response){
if(Debug.debug)
console.log("[ChromeCancer::check4conf] received response:",response);
loadConfig(response.response);
}
else{
if(Debug.debug)
console.log("%c[ChromeCancer::check4conf] sending message failed. retrying in 1s ... -- response for get-config:", "color: #f00", response);
setTimeout(_cancer_check4conf, 1000);
}
});
}
function _cancer_check4videos(){
var command = {};
command.cmd = "has-videos";
command.sender = "popup";
command.receiver = "uwbg";
browser.runtime.sendMessage(command, function(response){
if(response){
if(Debug.debug)
console.log("[ChromeCancer::check4videos] received response:",response);
if(response.response.hasVideos){
hasVideos = true;
openMenu(selectedMenu);
}
}
else{
if(Debug.debug)
console.log("%c[ChromeCancer::check4conf] sending message failed. retrying in 1s ... -- response for has-videos:", "color: #f00", response);
setTimeout(_cancer_check4videos, 1000);
}
});
}
function _cancer_check4conf2(){
var command = {};
command.cmd = "get-config-cancer";
command.sender = "popup";
command.receiver = "uwbg";
browser.runtime.sendMessage(command, function(response){
if(response){
if(Debug.debug)
console.log("[ChromeCancer::check4conf2 (cancer edit)] received response:",response);
loadConfig(response.response);
}
else{
if(Debug.debug)
console.log("%c[ChromeCancer::check4conf (cancer edit)] sending message failed. retrying in 1s ... -- response for get-config:", "color: #f00", response, chrome.extension.lastError);
setTimeout(_cancer_check4conf2, 1000);
}
});
}
function _cancer_check4videos2(){
var command = {};
command.cmd = "has-videos-cancer";
command.sender = "popup";
command.receiver = "uwbg";
browser.runtime.sendMessage(command, function(response){
if(response){
if(Debug.debug)
console.log("[ChromeCancer::check4videos2 (cancer edit)] received response:",response);
if(response.response.hasVideos){
hasVideos = true;
openMenu(selectedMenu);
}
}
else{
if(Debug.debug)
console.log("%c[ChromeCancer::check4conf2 (cancer edit)] sending message failed. retrying in 1s ... -- response for has-videos-cancer:", "color: #f00", response);
setTimeout(_cancer_check4videos2, 1000);
}
});
}
var ChromeCancer = {
recvmsg: _cancer_recvmsg,
receiveMessage_cs: _cancer_content_receiveMessage,
check4conf: _cancer_check4conf,
check4videos: _cancer_check4videos,
check4videos2: _cancer_check4videos2,
check4conf2: _cancer_check4conf2
}

View File

@ -12,7 +12,7 @@ var _com_chrome_tabquery_wrapper = async function(tabInfo){
var _com_queryTabs = async function(tabInfo){
if(BrowserDetect.usebrowser == "chrome"){
return _com_chrome_tabquery_wrapper(tabInfo);
return await _com_chrome_tabquery_wrapper(tabInfo);
}
else{
return browser.tabs.query(tabInfo);
@ -22,20 +22,26 @@ var _com_queryTabs = async function(tabInfo){
var _com_chrome_tabs_sendmsg_wrapper = async function(tab, message, options){
return new Promise(function (resolve, reject){
browser.tabs.sendMessage(tab, message, options, function(response){
// Chrome/js shittiness mitigation — remove this line and an empty array will be returned
var r = response;
console.log("what is this owo? ---> (response to tabs.sendMessage)", r);
resolve(r);
});
try{
browser.tabs.sendMessage(tab, message, /*options, */function(response){
console.log("TESTING what is this owo? (response)", response);
// Chrome/js shittiness mitigation — remove this line and an empty array will be returned
var r = response;
resolve(r);
});
}
catch(e){
reject(e);
}
});
}
var _com_sendMessage = async function(tab, message, options){
if(BrowserDetect.usebrowser == "chrome"){
var r = _com_chrome_tabs_sendmsg_wrapper(tab, message, options);
console.log("what is this owo? (should be a promise)", r);
var r = await _com_chrome_tabs_sendmsg_wrapper(tab, message, options);
console.log("TESTING what is this owo? (should be a promise)", r);
return r;
}
else{

View File

@ -4,48 +4,47 @@ async function main(){
await Settings.init();
browser.runtime.onMessage.addListener(_uwbg_rcvmsg);
if(BrowserDetect.usebrowser == "chrome")
browser.runtime.onMessage.addListener(ChromeCancer.recvmsg);
else
browser.runtime.onMessage.addListener(_uwbg_rcvmsg);
if(Debug.debug)
console.log("[uw-bg::main] listeners registered");
}
async function sendMessage(message){
console.log("SENDING MESSAGE TO CONTENT SCRIPT");
var tabs = await Comms.queryTabs({currentWindow: true, active: true});
if(Debug.debug)
console.log("[uw-bg::sendMessage] queried tabs, got this:", tabs);
if(Debug.debug)
console.log("[uw-bg::sendMessage] trying to send message", message, " to tab ", tabs[0], ". (all tabs:", tabs,")");
var response = await Comms.sendMessage(tabs[0].id, message);
var response = await browser.tabs.sendMessage(tabs[0].id, message);
console.log("[uw-bg::sendMessage] response is this:",response);
return response;
}
async function _uwbg_rcvmsg(message, sender, sendResponse){
async function _uwbg_rcvmsg(message){
if(Debug.debug){
console.log("[uw-bg::_uwbg_rcvmsg] received message", message);
}
message.sender = "uwbg";
message.receiver = "uw";
if(message.cmd == "has-videos"){
var response = await sendMessage(message);
if(Debug.debug){
console.log("[uw-bg::_uwbg_rcvmsg] received response!", message);
}
if(BrowserDetect.usebrowser == "firefox")
if(message.cmd == "has-videos"){
var response = await sendMessage(message);
if(Debug.debug){
console.log("[uw-bg::_uwbg_rcvmsg] received response for message", message, "response is this -->", response);
}
return Promise.resolve(response);
sendResponse({response: config});
return true;
}
}
if(message.cmd == "get-config"){
var config = {};
config.videoAlignment = Settings.miscFullscreenSettings.videoFloat;
config.arConf = {};
@ -72,14 +71,11 @@ async function _uwbg_rcvmsg(message, sender, sendResponse){
}
catch(ex){
console.log("%c[uw-bg::_uwbg_rcvmsg] there was something wrong with request for get-ardetect-active.", "color: #f00", ex);
if(Debug.debug)
console.log("%c[uw-bg::_uwbg_rcvmsg] there was something wrong with request for get-ardetect-active.", "color: #f00", ex);
}
if(BrowserDetect.usebrowser == "firefox")
return Promise.resolve({response: config});
sendResponse({response: config});
return true;
return Promise.resolve({response: config});
}
else if(message.cmd == "force-ar"){
sendMessage(message); // args: {cmd: string, newAr: number/"auto"}
@ -112,7 +108,6 @@ async function _uwbg_rcvmsg(message, sender, sendResponse){
Settings.save();
sendMessage("reload-settings");
}
}

View File

@ -83,9 +83,16 @@ async function main(){
fullScreenCheck(0);
});
browser.runtime.onMessage.addListener(receiveMessage);
// });
if(BrowserDetect.usebrowser == "firefox"){
if(Debug.debug)
console.log("[uw::main] detected firefox.");
browser.runtime.onMessage.addListener(receiveMessage);
}
else{
browser.runtime.onMessage.addListener(ChromeCancer.receiveMessage_cs)
}
}
var _main_fscheck_tries = 3;
@ -135,24 +142,22 @@ function fullScreenCheck(count) {
}
// comms
function receiveMessage(message, sender, sendResponse) {
function receiveMessage(message) {
if(Debug.debug)
console.log("[uw::receiveMessage] we received a message.", message);
if(message.cmd == "has-videos"){
var anyVideos = PageInfo.hasVideos();
return Promise.resolve({response: {"hasVideos": anyVideos }});
}
else if(message.cmd == "get-ardetect-active"){
var arDetect_active = ArDetect.isRunning();
if(BrowserDetect.usebrowser == "firefox")
return Promise.resolve({response: {"arDetect_active": arDetect_active }});
sendResponse({response: {"arDetect_active": arDetect_active }});
return true;
return Promise.resolve({response: {"arDetect_active": arDetect_active }});
}
else if(message.cmd == "force-ar"){
if(Debug.debug)
console.log("[uw::receiveMessage] we're being commanded to change aspect ratio to", message.newAr);

View File

@ -1,88 +0,0 @@
{
"manifest_version": 2,
"name": "Ultrawidify-git",
"version": "2.0.1",
"icons": {
"32":"res/icons/uw-32.png",
"64":"res/icons/uw-64.png"
},
"description": "Aspect ratio fixer for youtube that works around some people's disability to properly encode 21:9 (and sometimes, 16:9) videos.",
"background": {
"scripts": [
"js/dep/jquery-3.1.1.js",
"js/lib/BrowserDetect.js",
"js/lib/StorageManager.js",
"js/lib/Comms.js",
"js/conf/Debug.js",
"js/conf/Settings.js",
"js/conf/Keybinds.js",
"js/uw-bg.js"
]
},
"content_scripts": [{
"matches": ["*://*/*"],
"js": [
"js/dep/jquery-3.1.1.js",
"js/lib/BrowserDetect.js",
"js/lib/StorageManager.js",
"js/lib/Comms.js",
"js/conf/Debug.js",
"js/conf/Settings.js",
"js/conf/SitesConf.js",
"js/conf/Status.js",
"js/conf/ExtensionConf.js",
"js/lib/FullScreenDetect.js",
"js/modules/PageInfo.js",
"js/modules/ArDetect.js",
"js/modules/Resizer.js",
"js/conf/Keybinds.js",
"js/uw.js" ],
"all_frames": true
}],
"permissions": [
"tabs", "storage", "activeTab", "<all_urls>", "*://*.youtube.com/*", "*://youtube.com/*", "*://imdb.com/*", "*://*.imdb.com/*"
],
"browser_action": {
"default_icon": "res/icons/uw-32.png",
"default_popup": "res/popup/popup.html",
"default_title": "Uʟᴛʀᴀɪɪʏ"
},
"web_accessible_resources": [
"js/*",
"res/img/ytplayer-icons/zoom.png",
"res/img/ytplayer-icons/unzoom.png",
"res/img/ytplayer-icons/fitw.png",
"res/img/ytplayer-icons/fith.png",
"res/img/ytplayer-icons/reset.png",
"res/img/ytplayer-icons/settings.png",
"res/img/settings/about-bg.png",
"res/css/uw_common.css",
"res/css/uw_yt.css",
"res/css/uw_netflix.css",
"res/css/uw_settings.css"
],
"options_ui" : {
"page": "res/settings/settings.html",
"open_in_tab": true
}
}

View File

@ -1,7 +1,7 @@
{
"manifest_version": 2,
"name": "Ultrawidify",
"version": "2.0.1",
"name": "Ultrawidify-git",
"version": "2.0.2",
"icons": {
"32":"res/icons/uw-32.png",
@ -9,11 +9,31 @@
},
"description": "Aspect ratio fixer for youtube that works around some people's disability to properly encode 21:9 (and sometimes, 16:9) videos.",
"background": {
"scripts": [
"js/dep/jquery-3.1.1.js",
"js/dep/chrome/chrome-extension-async.js",
"js/lib/BrowserDetect.js",
"js/lib/StorageManager.js",
"js/lib/Comms.js",
"js/conf/Debug.js",
"js/conf/Settings.js",
"js/conf/Keybinds.js",
"js/lib/ChromeCancer.js",
"js/uw-bg.js"
]
},
"content_scripts": [{
"matches": ["*://*/*"],
"js": [
"js/dep/jquery-3.1.1.js",
"js/dep/chrome/chrome-extension-async.js",
"js/lib/BrowserDetect.js",
"js/lib/StorageManager.js",
@ -33,6 +53,8 @@
"js/conf/Keybinds.js",
"js/lib/ChromeCancer.js",
"js/uw.js" ],
"all_frames": true
}],
@ -41,6 +63,12 @@
"tabs", "storage", "activeTab", "<all_urls>", "*://*.youtube.com/*", "*://youtube.com/*", "*://imdb.com/*", "*://*.imdb.com/*"
],
"browser_action": {
"default_icon": "res/icons/uw-32.png",
"default_popup": "res/popup/popup.html",
"default_title": "Uʟᴛʀᴀɪɪʏ"
},
"web_accessible_resources": [
"js/*",

View File

@ -34,7 +34,8 @@ var hasVideos = false;
var _config;
var _changeAr_button_shortcuts = { "autoar":"none", "reset":"none", "219":"none", "189":"none", "169":"none" }
async function check4videos(){
function check4videos(){
var command = {};
command.cmd = "has-videos";
command.sender = "popup";
@ -58,7 +59,7 @@ async function check4videos(){
});
}
async function check4conf(){
function check4conf(){
var command = {};
command.cmd = "get-config";
command.sender = "popup";
@ -238,10 +239,8 @@ function showArctlButtons(){
document.addEventListener("click", (e) => {
// console.log("we clicked. e?",e);
function getcmd(e){
// console.log("extracting command from e", e);
var command = {};
command.sender = "popup";
@ -350,6 +349,10 @@ document.addEventListener("click", (e) => {
});
check4videos();
check4conf();
if(BrowserDetect.usebrowser == "firefox"){
check4videos();
check4conf();
}
else{
}

View File

@ -224,6 +224,8 @@
<!-- load all scripts. ordering is important! -->
<script src="../../js/dep/jquery-3.1.1.js" ></script>
<script src="../../js/dep/chrome/chrome-extension-async.js" ></script>
<script src="../../js/conf/Debug.js"></script>
<script src="../../js/lib/BrowserDetect.js"></script>
@ -237,6 +239,7 @@
"js/conf/Status.js",-->
<script src="../../js/conf/Settings.js"></script>
<script src="../../js/lib/ChromeCancer.js"></script>
<script src="./js/popup.js"></script>
</body>