Skip to content
This repository has been archived by the owner on Nov 6, 2023. It is now read-only.

Commit

Permalink
Revert #10852 (fixes #10864)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hainish committed Jul 6, 2017
1 parent c45e7fe commit 9a770ca
Show file tree
Hide file tree
Showing 8 changed files with 271 additions and 274 deletions.
228 changes: 114 additions & 114 deletions chromium/background.js

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions chromium/devtools-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,35 +43,35 @@ function display() {
chrome.runtime.sendMessage({
type: "getSmallHtml",
tabId: chrome.devtools.inspectedWindow.tabId,
}, response => {
}, function(response) {
e("SwitchPlannerDetails").innerHTML = response.html;
e("SwitchPlannerResults").style.display = "block";
});
}

window.onload = () => {
window.onload = function() {
// Open a connection to the background page. Right now this is only used
// by the background page so it knows when the devtools pane has closed.
// We don't receive messages from the background page currently, though that
// may be a future improvement. Sending messages to the background page doesn't
// require an existing connection.
chrome.runtime.connect({ name: "devtools-page" });

const checkbox = e("SwitchPlannerCheckbox");
checkbox.addEventListener("change", () => {
var checkbox = e("SwitchPlannerCheckbox");
checkbox.addEventListener("change", function() {
if (checkbox.checked) {
enableSwitchPlanner();
} else {
disableSwitchPlanner();
}
});

e("SwitchPlannerDetailsLink").addEventListener("click", () => {
e("SwitchPlannerDetailsLink").addEventListener("click", function() {
window.open("switch-planner.html?tab=" + chrome.devtools.inspectedWindow.tabId);
});
// Since this is rendered in a devtools console, we have to make clicks on the
// link open a new window.
e("MixedContentLink").addEventListener("click", e => {
e("MixedContentLink").addEventListener("click", function(e) {
window.open(e.target.href);
});
};
2 changes: 1 addition & 1 deletion chromium/devtools.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
chrome.devtools.panels.create("HTTPS Everywhere",
"icons/icon-active-38.png",
"devtools-panel.html",
panel => {
function(panel) {
}
);
90 changes: 45 additions & 45 deletions chromium/popup.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"use strict";

const backgroundPage = chrome.extension.getBackgroundPage();
let stableRules = null;
let unstableRules = null;
const hostReg = /.*\/\/[^$/]*\//;
const storage = backgroundPage.storage;
var backgroundPage = chrome.extension.getBackgroundPage();
var stableRules = null;
var unstableRules = null;
var hostReg = /.*\/\/[^$/]*\//;
var storage = backgroundPage.storage;

function e(id) {
return document.getElementById(id);
Expand All @@ -18,7 +18,7 @@ function e(id) {
function toggleRuleLine(checkbox, ruleset) {
ruleset.active = checkbox.checked;

if (ruleset.active !== ruleset.default_state) {
if (ruleset.active != ruleset.default_state) {
localStorage[ruleset.name] = ruleset.active;
} else {
delete localStorage[ruleset.name];
Expand All @@ -37,54 +37,54 @@ function toggleRuleLine(checkbox, ruleset) {
function appendRuleLineToListDiv(ruleset, list_div) {

// parent block for line
const line = document.createElement("div");
var line = document.createElement("div");
line.className = "rule checkbox";

// label "container"
const label = document.createElement("label");
var label = document.createElement("label");

// checkbox
const checkbox = document.createElement("input");
var checkbox = document.createElement("input");
checkbox.type = "checkbox";
if (ruleset.active) {
checkbox.setAttribute("checked", "");
}
checkbox.onchange = ev => {
checkbox.onchange = function(ev) {
toggleRuleLine(checkbox, ruleset);
};
label.appendChild(checkbox);

// favicon (from chrome's cache)
const favicon = document.createElement("img");
var favicon = document.createElement("img");
favicon.className = "favicon";
favicon.src = "chrome://favicon/";
for (const rule of ruleset.rules) {
const host = hostReg.exec(rule.to);
for (var i=0; i < ruleset.rules.length; i++) {
var host = hostReg.exec(ruleset.rules[i].to);
if (host) {
favicon.src += host[0];
break;
}
}
const xhr = new XMLHttpRequest();
var xhr = new XMLHttpRequest();
try {
xhr.open("GET", favicon.src, true);
label.appendChild(favicon);
} catch (e) {}

// label text
const text = document.createElement("span");
var text = document.createElement("span");
text.innerText = ruleset.name;
if (ruleset.note.length) {
text.title = ruleset.note;
}

if(ruleset.note === "user rule") {
const remove = document.createElement("img");
if(ruleset.note == "user rule") {
var remove = document.createElement("img");
remove.src = chrome.extension.getURL("remove.png");
remove.className = "remove";
line.appendChild(remove);

remove.addEventListener("click", () => {
remove.addEventListener("click", function(){
backgroundPage.removeRule(ruleset);
list_div.removeChild(line);
});
Expand Down Expand Up @@ -129,11 +129,11 @@ function toggleEnabledDisabled() {
* @param tabArray
*/
function gotTab(tabArray) {
const activeTab = tabArray[0];
const rulesets = backgroundPage.activeRulesets.getRulesets(activeTab.id);
var activeTab = tabArray[0];
var rulesets = backgroundPage.activeRulesets.getRulesets(activeTab.id);

for (const r in rulesets) {
const listDiv = stableRules;
for (var r in rulesets) {
var listDiv = stableRules;
if (!rulesets[r].default_state) {
listDiv = unstableRules;
}
Expand All @@ -160,24 +160,24 @@ document.addEventListener("DOMContentLoaded", function () {
document.getElementById('onoffswitch').addEventListener('click', toggleEnabledDisabled);

// Print the extension's current version.
const the_manifest = chrome.runtime.getManifest();
const version_info = document.getElementById('current-version');
var the_manifest = chrome.runtime.getManifest();
var version_info = document.getElementById('current-version');
version_info.innerText = the_manifest.version;

// Set up toggle checkbox for HTTP nowhere mode
getOption_('httpNowhere', false, item => {
const httpNowhereCheckbox = document.getElementById('http-nowhere-checkbox');
getOption_('httpNowhere', false, function(item) {
var httpNowhereCheckbox = document.getElementById('http-nowhere-checkbox');
httpNowhereCheckbox.addEventListener('click', toggleHttpNowhere, false);
const httpNowhereEnabled = item.httpNowhere;
var httpNowhereEnabled = item.httpNowhere;
if (httpNowhereEnabled) {
httpNowhereCheckbox.setAttribute('checked', '');
}
});

// auto-translate all elements with i18n attributes
const elements = document.querySelectorAll("[i18n]");
for (const element of elements) {
elements.innerHTML = chrome.i18n.getMessage(elements.getAttribute("i18n"));
var elem = document.querySelectorAll("[i18n]");
for (var i=0; i < elem.length; i++) {
elem[i].innerHTML = chrome.i18n.getMessage(elem[i].getAttribute("i18n"));
}

// other translations
Expand All @@ -186,7 +186,7 @@ document.addEventListener("DOMContentLoaded", function () {
});


function escapeForRegex(value) {
var escapeForRegex = function( value ) {
return value.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, "\\$&");
};

Expand All @@ -202,61 +202,61 @@ function show(elem) {
* Handles the manual addition of rules
*/
function addManualRule() {
chrome.tabs.query({ active: true, currentWindow: true }, tab => {
chrome.tabs.query({ active: true, currentWindow: true }, function(tab) {
hide(e("add-rule-link"));
show(e("add-new-rule-div"));
const newUrl = document.createElement('a');
var newUrl = document.createElement('a');
newUrl.href = tab[0].url;
newUrl.protocol = "https:";
e("new-rule-host").value = newUrl.host;
const oldUrl = document.createElement('a');
var oldUrl = document.createElement('a');
oldUrl.href = tab[0].url;
oldUrl.protocol = "http:";
const oldMatcher = "^" + escapeForRegex(oldUrl.protocol + "//" + oldUrl.host+ "/");
var oldMatcher = "^" + escapeForRegex(oldUrl.protocol + "//" + oldUrl.host+ "/");
e("new-rule-regex").value = oldMatcher;
const redirectPath = newUrl.protocol + "//" + newUrl.host + "/";
var redirectPath = newUrl.protocol + "//" + newUrl.host + "/";
e("new-rule-redirect").value = redirectPath;
e("new-rule-name").value = "Manual rule for " + oldUrl.host;
e("add-new-rule-button").addEventListener("click", () => {
const params = {
e("add-new-rule-button").addEventListener("click", function() {
var params = {
host : e("new-rule-host").value,
redirectTo : e("new-rule-redirect").value,
urlMatcher : e("new-rule-regex").value
};
backgroundPage.addNewRule(params, () => {
backgroundPage.addNewRule(params, function() {
location.reload();
});
});

e("cancel-new-rule").addEventListener("click", () => {
e("cancel-new-rule").addEventListener("click", function() {
show(e("add-rule-link"));
hide(e("add-new-rule-div"));
});
e("new-rule-show-advanced-link").addEventListener("click", () => {
e("new-rule-show-advanced-link").addEventListener("click", function() {
show(e("new-rule-advanced"));
hide(e("new-rule-regular-text"));
});
e("new-rule-hide-advanced-link").addEventListener("click", () => {
e("new-rule-hide-advanced-link").addEventListener("click", function() {
hide(e("new-rule-advanced"));
show(e("new-rule-regular-text"));
});
});
}

function toggleHttpNowhere() {
getOption_('httpNowhere', false, item => {
getOption_('httpNowhere', false, function(item) {
setOption_('httpNowhere', !item.httpNowhere);
});
}

function getOption_(opt, defaultOpt, callback) {
const details = {};
var details = {};
details[opt] = defaultOpt;
return storage.get(details, callback);
}

function setOption_(opt, value) {
const details = {};
var details = {};
details[opt] = value;
return storage.set(details);
}
Loading

0 comments on commit 9a770ca

Please sign in to comment.