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

Commit

Permalink
DRYing out some of the util.js functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
Hainish committed Sep 17, 2018
1 parent 50ec065 commit bcbfbed
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 36 deletions.
2 changes: 1 addition & 1 deletion chromium/pages/cancel/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ <h1 id="https-everywhere"><img src="../../images/banner-red.png" alt="HTTPS Ever
<p data-i18n="cancel_he_blocking_explainer"></p>
<p id="url-paragraph"><span id="url-label">URL: </span><a href="#" id="originURL"></a></p>
<script src="../translation.js"></script>
<script src="../send-message.js"></script>
<script src="../util.js"></script>
<script src="ux.js"></script>
</body>
</html>
2 changes: 1 addition & 1 deletion chromium/pages/debugging-rulesets/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<textarea id="codemirror-textarea"></textarea>
<button type="button" id="save-button">Save</button>
<div id="saved-text">Saved!</div>
<script src="../send-message.js"></script>
<script src="../util.js"></script>
<script src="ux.js"></script>
</body>
</html>
2 changes: 1 addition & 1 deletion chromium/pages/devtools/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="utf-8">
<title></title>
<script src="../send-message.js"></script>
<script src="../util.js"></script>
<script src="ux.js"></script>
</head>
<body></body>
Expand Down
1 change: 0 additions & 1 deletion chromium/pages/options/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@

<script src="ux.js"></script>
<script src="../translation.js"></script>
<script src="../send-message.js"></script>
<script src="../util.js"></script>
</body>
</html>
2 changes: 1 addition & 1 deletion chromium/pages/popup/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<link href="style.css" rel="stylesheet">
<script src="ux.js"></script>
<script src="../translation.js"></script>
<script src="../send-message.js"></script>
<script src="../util.js"></script>
</head>
<body>
<header>
Expand Down
29 changes: 5 additions & 24 deletions chromium/pages/popup/ux.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
/* global e */
/* global hide */
/* global show */
/* global sendMessage */
/* global getOption_ */
/* global setOption_ */

"use strict";

function e(id) {
return document.getElementById(id);
}

/**
* Handles rule (de)activation in the popup
*/
Expand Down Expand Up @@ -209,14 +210,6 @@ var escapeForRegex = function( value ) {
return value.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, "\\$&");
};

function hide(elem) {
elem.style.display = "none";
}

function show(elem) {
elem.style.display = "block";
}

function showEnableOrDisable(url, disabled) {
if (["http:", "https:", "ftp:"].indexOf(url.protocol) != -1) {
const disableLink = e("disable-on-this-site");
Expand Down Expand Up @@ -311,18 +304,6 @@ function toggleHttpNowhere() {
});
}

function getOption_(opt, defaultOpt, callback) {
var details = {};
details[opt] = defaultOpt;
sendMessage("get_option", details, callback);
}

function setOption_(opt, value, callback) {
var details = {};
details[opt] = value;
sendMessage("set_option", details, callback);
}

function getTab(callback) {
let url = new URL(window.location.href);
if (url.searchParams.has('tabId')) {
Expand Down
7 changes: 0 additions & 7 deletions chromium/pages/send-message.js

This file was deleted.

12 changes: 12 additions & 0 deletions chromium/pages/util.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/* exported e */
/* exported hide */
/* exported show */
/* exported sendMessage */
/* exported getOption_ */
/* exported setOption_ */

"use strict";

Expand All @@ -20,6 +22,10 @@ function show(elem) {
elem.style.display = "block";
}

function sendMessage(type, object, callback) {
chrome.runtime.sendMessage({ type, object }, callback);
}

/**
* Get an option from global settings
* @param {string} opt
Expand All @@ -32,3 +38,9 @@ function getOption_(opt, defaultOpt, callback) {
details[opt] = defaultOpt;
sendMessage("get_option", details, callback);
}

function setOption_(opt, value, callback) {
var details = {};
details[opt] = value;
sendMessage("set_option", details, callback);
}

0 comments on commit bcbfbed

Please sign in to comment.