Reworked popup warnings. Chrome doesn't work again.

This commit is contained in:
Tamius Han 2018-02-02 00:21:29 +01:00
parent 174c987690
commit b13eff44e3
5 changed files with 119 additions and 70 deletions

View File

@ -18,11 +18,17 @@ var _se_init = async function(neverFlushStored){
console.log("[Settings::_se_init()] settings saved in localstorage are:", newSettings, " - if that's empty, it's gonna be replaced by this:", JSON.stringify(this), ")");
if ((Object.keys(newSettings).length === 0 && newSettings.constructor === Object)){
console.log("[Settings::_se_init()] replacing settings");
StorageManager.setopt({"uw-settings": JSON.stringify(this)});
}
else{
for (var k in newSettings)
this[k] = newSettings[k];
var actualSettings = JSON.parse(newSettings["uw-settings"]);
if(Debug.debug)
console.log("[Settings::_se_init()] parsed settings:", actualSettings);
for (var k in actualSettings)
this[k] = actualSettings[k];
}
if(Debug.debug)

View File

@ -1,7 +1,22 @@
var BgVars = {
arIsActive: true,
hasVideos: false
hasVideos: false,
currentSite: ""
}
function extractHostname(url){
// extract hostname
if (url.indexOf("://") > -1) { //find & remove protocol (http, ftp, etc.) and get hostname
hostname = url.split('/')[2];
}
else {
hostname = url.split('/')[0];
}
hostname = hostname.split(':')[0]; //find & remove port number
hostname = hostname.split('?')[0]; //find & remove "?"
return hostname;
}
async function main(){
@ -21,6 +36,11 @@ async function main(){
if(Debug.debug)
console.log("[uw-bg::main] listeners registered");
// add currentSite
var tabs = await Comms.getActiveTab();
BgVars.currentSite = extractHostname(tabs[0].url);
}
async function _uwbg_onTabSwitched(activeInfo){
@ -28,8 +48,14 @@ async function _uwbg_onTabSwitched(activeInfo){
if(Debug.debug)
console.log("[uw-bg::onTabSwitched] TAB CHANGED, GETTING INFO FROM MAIN TAB");
var tabId = activeInfo.tabId; // just for readability
var tab = await browser.tabs.get(tabId);
BgVars.currentSite = extractHostname(tab.url);
// this can fail. This might also not return a promise? Check that.
var videoFrameList = await Comms.sendToEach({"cmd":"has-videos"}, tabId);
if(Debug.debug)
@ -125,6 +151,49 @@ function _uwbg_rcvmsg(message, sender, sendResponse){
_uwbg_registerVideo(sender.tab.id);
}
else if(message.cmd == "uw-enabled-for-site"){
var wlindex = Settings.whitelist.indexOf(BgVars.currentSite);
var blindex = Settings.blacklist.indexOf(BgVars.currentSite);
var mode = "default";
if(wlindex > -1)
mode = "whitelist";
if(blindex > -1)
mode = "blacklist";
if(Debug.debug){
console.log("[uw::receiveMessage] is this site: ", BgVars.currentSite, "\n\n", "whitelisted or blacklisted? whitelist:", (wlindex > -1), "; blacklist:", (blindex > -1), "; mode (return value):", mode, "\nwhitelist:",Settings.whitelist,"\nblacklist:",Settings.blacklist);
}
if(BrowserDetect.usebrowser == "firefox")
return Promise.resolve({response: mode});
try{
sendResponse({response: mode});
}
catch(chromeIsShitError){};
return true;
}
else if(message.cmd == "enable-for-site"){
var wlindex = Settings.whitelist.indexOf(BgVars.currentSite);
var blindex = Settings.blacklist.indexOf(BgVars.currentSite);
if(wlindex > -1)
Settings.whitelist.splice(BgVars.currentSite, 1);
if(blindex > -1)
Settings.blacklist.splice(BgVars.currentSite, 1);
if(message.option == "whitelist")
Settings.whitelist.push(BgVars.currentSite);
if(message.option == "blacklist")
Settings.blacklist.push(BgVars.currentSite);
Settings.save();
}
}

View File

@ -94,8 +94,7 @@ var _video_recheck_counter = 0;
var _video_recheck_period = 60; // on this many retries
function ghettoOnChange(){
// console.log("..");
// console.log("events:", $._data($(document)[0], "events"));
if(_video_recheck_counter++ > _video_recheck_period){
_video_recheck_counter = 0;
@ -215,50 +214,6 @@ function receiveMessage(message, sender, sendResponse) {
else if(message.cmd == "reload-settings"){
Settings.reload();
}
else if(message.cmd == "uw-enabled-for-site"){
var site = window.location.hostname;
var wlindex = Settings.whitelist.indexOf(site);
var blindex = Settings.blacklist.indexOf(site);
var mode = "default";
if(wlindex > -1)
mode = "whitelist";
if(blindex > -1)
mode = "blacklist";
if(Debug.debug){
console.log("[uw::receiveMessage] is this site whitelisted or blacklisted? whitelist:", (wlindex > -1), "; blacklist:", (blindex > -1), "; mode (return value):", mode, "\nwhitelist:",Settings.whitelist,"\nblacklist:",Settings.blacklist);
}
if(BrowserDetect.usebrowser == "firefox")
return Promise.resolve({response: mode});
try{
sendResponse({response: mode});
}
catch(chromeIsShitError){};
return true;
}
else if(message.cmd == "enable-for-site"){
var site = window.location.hostname;
var wlindex = Settings.whitelist.indexOf(site);
var blindex = Settings.blacklist.indexOf(site);
if(wlindex > -1)
Settings.whitelist.splice(site, 1);
if(blindex > -1)
Settings.blacklist.splice(site, 1);
if(message.option == "whitelist")
Settings.whitelist.push(site);
if(message.option == "blacklist")
Settings.blacklist.push(site);
Settings.save(Settings);
}
if(message.cmd == "testing"){
if(Browserdetect.usebrowser = "firefox")
return Promise.resolve({response: "test response hier"});

View File

@ -4,7 +4,7 @@ if(Debug.debug)
document.getElementById("uw-version").textContent = browser.runtime.getManifest().version;
var Menu = {};
Menu.noVideo = document.getElementById("no-videos-display");
// Menu.noVideo = document.getElementById("no-videos-display");
Menu.general = document.getElementById("extension-mode");
Menu.thisSite = document.getElementById("settings-for-current-site");
Menu.arSettings = document.getElementById("aspect-ratio-settings");
@ -66,6 +66,10 @@ async function sendMessage(message){
return response;
}
function hideWarning(warn){
document.getElementById(warn).classList.add("hidden");
}
function check4videos(){
Comms.sendToBackgroundScript({cmd: "has-videos"})
@ -75,7 +79,8 @@ function check4videos(){
}
if(response.response.hasVideos){
hasVideos = true;
openMenu(selectedMenu);
// openMenu(selectedMenu);
hideWarning("no-videos-warning");
}
})
.catch(error => {
@ -104,7 +109,7 @@ function check4conf(){
}
function check4siteStatus(){
Comms.sendToMain({cmd: "uw-enabled-for-site"})
Comms.sendToBackgroundScript({cmd: "uw-enabled-for-site"})
.then(response => {
if(Debug.debug)
console.log("[popup::check4siteStatus] received response:", response);
@ -208,13 +213,13 @@ function openMenu(menu){
}
if(menu == "arSettings" || menu == "cssHacks" ){
if(!hasVideos)
Menu.noVideo.classList.remove("hidden");
else{
// if(!hasVideos)
// Menu.noVideo.classList.remove("hidden");
// else{
Menu[menu].classList.remove("hidden");
if(Debug.debug){
console.log("[popup.js::openMenu] unhid", menu, "| element: ", Menu[menu]);
}
// }
}
}
else{
@ -224,10 +229,10 @@ function openMenu(menu){
}
}
if(menu != "noVideo"){
selectedMenu = menu;
MenuTab[menu].classList.add("selected");
}
// if(menu != "noVideo"){
// selectedMenu = menu;
// MenuTab[menu].classList.add("selected");
// }
}
function _arctl_onclick(command){
@ -280,7 +285,7 @@ function toggleSite(option){
if(Debug.debug)
console.log("[popup::toggleSite] toggling extension 'should I work' status to", option, "on current site");
Comms.sendToMain({cmd:"enable-for-site", option:option});
Comms.sendToBackgroundScript({cmd:"enable-for-site", option:option});
}
document.addEventListener("click", (e) => {
@ -422,7 +427,8 @@ document.addEventListener("click", (e) => {
return true;
});
hideWarning("script-not-running-warning");
openMenu(selectedMenu);
check4videos();
check4conf();
check4siteStatus();

View File

@ -108,6 +108,23 @@
.w24 {
width: 100px;
}
.warning {
/*background-*/color: #d6ba4a;
/* color: #000; */
padding-left: 35px;
float: right;
}
.warning::before {
content: "⚠ ";
display: inline-block;
font-weight: bold;
font-size: 2.5em;
margin-left: -35px;
padding-right: 10px;
/* top: 0px; */
float: left;
}
.button:hover {
color: #fff;
background-color: #433221;
@ -153,13 +170,7 @@
</div>
</div>
<div class="right-side">
<div id="no-videos-display" class="suboption">
<p class="label center">No videos have been found on this page.</p><p>If there <i>is</i> a video on this page, then you're seeing this message for one of these reasons:</p>
<ul><li>Page hasn't finished loading<small><br/><span class="smallcaps">Note</span>: webextensions only start working when page is fully loaded.</small></li>
<li>The video is embedded / in an iframe.<small><br/>This is a known issue/limitation. Use keyboard shortcuts to correct aspect ratio.</small></li>
<li>Hamster Rajko is on strike.<small><br/>(Close this popup and reopen in a few seconds)</small></li></ul>
<p><u>Keyboard shortcuts:</u><br/>* <b>A</b> - attempt automatic detection<br/>* <b>W</b> - fit to width<br/>* <b>E</b> - fit to height<br/>* <b>R</b> - reset/stop automatic detection<br/><br/>Force aspect ratio:<br/>* <b>S</b>: 16:9<br/>* <b>D</b>: 21:9<br/>* <b>X</b>: 2:1</p>
</div>
<div id="script-not-running-warning" class="warning">If you see this line, then your browser didn't start the popup script yet. This is a problem caused by the browser. Please wait a few seconds.</div>
<div id="extension-mode" class="suboption hidden">
<p>How should extension work in general?<br/><small>NOTE: settings will be applied when page is reloaded.</small></p>
@ -185,11 +196,13 @@
<input type="radio" class="extensionEnabledOnCurrentSite" name="mode" value="whitelist" > Always (whitelist)<br/>
<input type="radio" class="extensionEnabledOnCurrentSite" name="mode" value="blacklist" > Never (blacklist)<br/>
</form>
<small>NOTE: this settings <b>don't</b> apply to videos embedded from other sites.</small>
<small>NOTE: this settings <b>don't</b> apply to videos embedded from other sites. This option takes effect after page reload.</small>
</div>
<div id="aspect-ratio-settings" class="suboption hidden">
<div id="no-videos-warning" class="warning">No videos were detected on this page. The buttons may not work at all. Check that this site is not blacklisted and reload the page.</div>
<div class="row">
<span class="label">Force aspect ratio:</span>
<div class="button-row">