Popup now works on Chrome as well.
This commit is contained in:
parent
33acbe5015
commit
d4a6901d7d
@ -1,46 +0,0 @@
|
||||
// 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_popup_port;
|
||||
var _cancer_uwbg_popup_port;
|
||||
|
||||
var _cancer_popup_handleCallbacks = function (message){
|
||||
if(message.cmd == "has-video-response"){
|
||||
if(message.response){
|
||||
if(message.response.hasVideos){
|
||||
hasVideos = true;
|
||||
openMenu();
|
||||
}
|
||||
}
|
||||
}
|
||||
if(message.cmd == "get-config-response"){
|
||||
if(message.response){
|
||||
loadConfig(message.response);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var _cancer_init_popup = function() {
|
||||
var _cancer_popup_port = browser.runtime.connect({name: "_uw_bg_popup"});
|
||||
|
||||
_cancer_popup_port.onMessage.addListener(_cancer_handleCallbacks);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
var ChromeCancer = {
|
||||
recvmsg: _cancer_recvmsg,
|
||||
receiveMessage_cs: _cancer_content_receiveMessage,
|
||||
check4conf: _cancer_check4conf,
|
||||
check4videos: _cancer_check4videos,
|
||||
check4videos2: _cancer_check4videos2,
|
||||
check4conf2: _cancer_check4conf2
|
||||
}*/
|
@ -146,26 +146,6 @@ var _res_char = function(newAr, video, player){
|
||||
_res_setVideoAr(new_ar, video, player);
|
||||
}
|
||||
|
||||
// autochar: function(){
|
||||
//
|
||||
// if(debugmsg || debugmsg_autoar)
|
||||
// console.log("uw::autochar | starting. Did we get ar?",char_got_ar,"What about arx and ary?",char_arx,char_ary);
|
||||
//
|
||||
// if(!char_got_ar)
|
||||
// return;
|
||||
//
|
||||
// if(!char_arx || !char_ary)
|
||||
// return;
|
||||
//
|
||||
// var ar = char_arx / char_ary;
|
||||
// if(ar){
|
||||
// setBestFit(ar);
|
||||
// last_whatdo = {type: "autoar", what_do: "autoar"};
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* Tukaj povemo, kakšno razmerje stranic ima video.
|
||||
@ -261,82 +241,6 @@ var setVideoAr = function(aspect_ratio, video, player){
|
||||
this._res_applyCss(nv);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// // Ta funkcija ugotovi, kako se kvadrat s podanim razmerjem stranic najbolj prilega ekranu
|
||||
// // Predpostavimo, da so ćrne obrobe vselej zgoraj in spodaj, nikoli levo in desno.
|
||||
// //
|
||||
// // This function determines how a rectangle with a given aspect ratio best fits the monitor
|
||||
// // We assume letterbox is always letterbox, never pillarbox.
|
||||
// var _res_setBestFit = function(ar){
|
||||
// if(debugmsg || debugmsg_autoar)
|
||||
// console.log("uw::setBestFit | got ar:",ar);
|
||||
//
|
||||
// var player = {width: PLAYER.clientWidth, height: PLAYER.clientHeight};
|
||||
// var player_ar = player.width / player.height;
|
||||
//
|
||||
// var evideo = $("video")[0];
|
||||
// var video = {width: evideo.videoWidth, height: evideo.videoHeight};
|
||||
// var video_ar = video.width / video.height;
|
||||
//
|
||||
// // Ob predpostavki, da je argument 'ar' pravilen, naračunamo dimenzije videa glede na širino in višino predvajalnika
|
||||
// // Kot rezultat laho dobimo dve možnosti:
|
||||
// // A: naračunana širina je širša, kot naš zaslon —> za računanje uporabimo širino (letterbox zgoraj/spodaj,
|
||||
// // levo/desno pa ne)
|
||||
// // B: naračunana širina je ožja, kot naš zaslon —> za računanje uporabimo višino (letterbox levo/desno,
|
||||
// // zgoraj/spodaj pa ne)
|
||||
//
|
||||
// if(debugmsg || debugmsg_autoar)
|
||||
// console.log("uw::setBestFit | here's all we got. ar:",ar,"player:",player,"video:",video);
|
||||
//
|
||||
// var tru_width = player.height * ar;
|
||||
// var tru_height = player.width / ar;
|
||||
//
|
||||
// var nv = {w: "", h: "", top: "", left: ""};
|
||||
//
|
||||
// if(ar >= video_ar){
|
||||
// if(ar >= player_ar){
|
||||
// if(debugmsg || debugmsg_autoar)
|
||||
// console.log("uw::setBestFit | aspect ratio is wider than player ar.")
|
||||
// nv.h = player.width / video_ar;
|
||||
// nv.w = nv.h * ar;
|
||||
// }
|
||||
// else{
|
||||
// if(debugmsg || debugmsg_autoar)
|
||||
// console.log("uw::setBestFit | aspect ratio is narrower than player ar.", (player.height * ar), nv)
|
||||
// nv.w = player.height * ar;
|
||||
// nv.h = nv.w / video_ar;
|
||||
// }
|
||||
// }
|
||||
// else{
|
||||
// if(ar >= player_ar){
|
||||
// if(debugmsg || debugmsg_autoar)
|
||||
// console.log("uw::setBestFit | aspect ratio is wider than player ar.")
|
||||
// nv.h = player.width / ar;
|
||||
// nv.w = nv.h * video_ar;
|
||||
// }
|
||||
// else{
|
||||
// if(debugmsg || debugmsg_autoar)
|
||||
// console.log("uw::setBestFit | aspect ratio is narrower than player ar.", (player.height * ar), nv)
|
||||
// nv.w = player.height * video_ar;
|
||||
// nv.h = nv.w / ar;
|
||||
// }
|
||||
// }
|
||||
// if(debugmsg || debugmsg_autoar)
|
||||
// console.log("uw::setBestFit | new video width and height processed. nv so far:", nv)
|
||||
//
|
||||
// nv.top = (player.height - nv.h)/2;
|
||||
// nv.left = (player.width - nv.w)/2;
|
||||
//
|
||||
// if(debugmsg || debugmsg_autoar)
|
||||
// console.log("uw::setBestFit | tru width:",tru_width,"(player width:",player.width,"); new video size:",nv);
|
||||
//
|
||||
// _res_applyCss(nv);
|
||||
// console.log("uw::setBestFit | css applied");
|
||||
// }
|
||||
|
||||
|
||||
|
||||
var _res_reset = function(force){
|
||||
dimensions = {top: "", left: "", width: "100%", height: "100%"};
|
||||
|
||||
@ -586,9 +490,6 @@ function _res_applyCss(dimensions){
|
||||
else if(styleArray[i].startsWith("position:")){
|
||||
styleArray[i] = dimensions.position;
|
||||
}
|
||||
else if(styleArray[i].startsWith("object-fit:")){
|
||||
styleArray[i] = dimensions.objectFit;
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
|
33
js/uw.js
33
js/uw.js
@ -74,25 +74,17 @@ async function main(){
|
||||
|
||||
_main_last_fullscreen = FullScreenDetect.isFullScreen();
|
||||
|
||||
document.addEventListener("mozfullscreenchange", function( event ) {
|
||||
|
||||
// Poslušamo za lovljenje spremembe iz navadnega načina v celozaslonski način in obratno.
|
||||
// Listen for and handle changes to and from full screen.
|
||||
$(document).bind('webkitfullscreenchange mozfullscreenchange fullscreenchange MSFullscreenChange', function(){
|
||||
if(Debug.debug){
|
||||
// console.log("[uw::mozfullscreenchange] full screen state is changing. event:", event);
|
||||
console.log("%c[uw::mozfullscreenchange] are we in full screen?","color: #aaf", FullScreenDetect.isFullScreen());
|
||||
console.log("%c[uw::onfullscreenchange] are we in full screen?","color: #aaf", FullScreenDetect.isFullScreen());
|
||||
}
|
||||
fullScreenCheck(0);
|
||||
|
||||
});
|
||||
|
||||
|
||||
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;
|
||||
@ -142,15 +134,18 @@ function fullScreenCheck(count) {
|
||||
}
|
||||
|
||||
// comms
|
||||
function receiveMessage(message) {
|
||||
function receiveMessage(message, sender, sendResponse) {
|
||||
if(Debug.debug)
|
||||
console.log("[uw::receiveMessage] we received a message.", message);
|
||||
|
||||
if(message.cmd == "has-videos"){
|
||||
var anyVideos = PageInfo.hasVideos();
|
||||
|
||||
if(BrowserDetect.usebrowser == "firefox")
|
||||
return Promise.resolve({response: {"hasVideos": anyVideos }});
|
||||
|
||||
|
||||
sendResponse({response: {"hasVideos":anyVideos}});
|
||||
return true;
|
||||
}
|
||||
else if(message.cmd == "get-config"){
|
||||
|
||||
@ -169,7 +164,11 @@ function receiveMessage(message) {
|
||||
// assume current is same as global & change that when you get response from content script
|
||||
config.arConf.enabled_current = ArDetect.isRunning();
|
||||
|
||||
if(BrowserDetect.usebrowser == "firefox")
|
||||
return Promise.resolve({response: config});
|
||||
|
||||
sendResponse({response: config});
|
||||
return true;
|
||||
}
|
||||
|
||||
else if(message.cmd == "force-ar"){
|
||||
@ -202,7 +201,11 @@ function receiveMessage(message) {
|
||||
}
|
||||
|
||||
if(message.cmd == "testing"){
|
||||
if(Browserdetect.usebrowser = "firefox")
|
||||
return Promise.resolve({response: "test response hier"});
|
||||
|
||||
sendResponse({response: "test response hier"});
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -10,25 +10,6 @@
|
||||
|
||||
"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": [
|
||||
@ -53,8 +34,6 @@
|
||||
|
||||
"js/conf/Keybinds.js",
|
||||
|
||||
"js/lib/ChromeCancer.js",
|
||||
|
||||
"js/uw.js" ],
|
||||
"all_frames": true
|
||||
}],
|
||||
@ -66,7 +45,7 @@
|
||||
"browser_action": {
|
||||
"default_icon": "res/icons/uw-32.png",
|
||||
"default_popup": "res/popup/popup.html",
|
||||
"default_title": "Uʟᴛʀᴀᴡɪᴅɪꜰʏ"
|
||||
"default_title": "Ultrawidify"
|
||||
},
|
||||
|
||||
"web_accessible_resources": [
|
||||
|
@ -35,21 +35,21 @@ var _config;
|
||||
var _changeAr_button_shortcuts = { "autoar":"none", "reset":"none", "219":"none", "189":"none", "169":"none" }
|
||||
|
||||
|
||||
async function test(){
|
||||
var message = {cmd: "testing"};
|
||||
try{
|
||||
var tabs = await Comms.queryTabs({currentWindow: true, active: true});
|
||||
if(Debug.debug)
|
||||
console.log("[popup.js::test] trying to send message", message, " to tab ", tabs[0], ". (all tabs:", tabs,")");
|
||||
|
||||
var response = await browser.tabs.sendMessage(tabs[0].id, message);
|
||||
console.log("[popup.js::test] response is this:",response);
|
||||
}
|
||||
catch(e){
|
||||
console.log("[popup.js::test] sending message failed. prolly cos browser.tabs no worky?", e);
|
||||
}
|
||||
}
|
||||
test();
|
||||
// async function test(){
|
||||
// var message = {cmd: "testing"};
|
||||
// try{
|
||||
// var tabs = await Comms.queryTabs({currentWindow: true, active: true});
|
||||
// if(Debug.debug)
|
||||
// console.log("[popup.js::test] trying to send message", message, " to tab ", tabs[0], ". (all tabs:", tabs,")");
|
||||
//
|
||||
// var response = await browser.tabs.sendMessage(tabs[0].id, message);
|
||||
// console.log("[popup.js::test] response is this:",response);
|
||||
// }
|
||||
// catch(e){
|
||||
// console.log("[popup.js::test] sending message failed. prolly cos browser.tabs no worky?", e);
|
||||
// }
|
||||
// }
|
||||
// test();
|
||||
|
||||
|
||||
|
||||
@ -370,10 +370,5 @@ document.addEventListener("click", (e) => {
|
||||
});
|
||||
|
||||
|
||||
if(BrowserDetect.usebrowser == "firefox"){
|
||||
check4videos();
|
||||
check4conf();
|
||||
}
|
||||
else{
|
||||
|
||||
}
|
||||
|
@ -232,14 +232,7 @@
|
||||
<script src="../../js/lib/StorageManager.js"></script>
|
||||
<script src="../../js/lib/Comms.js"></script>
|
||||
|
||||
<!-- the following scripts aren't included yet. if they're needed, they need to be added in this order -->
|
||||
<!-- "js/conf/Debug.js",
|
||||
"js/conf/Settings.js",
|
||||
"js/conf/SitesConf.js",
|
||||
"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>
|
||||
|
Loading…
Reference in New Issue
Block a user