Skip to content

Commit

Permalink
Merge branch 'global-exclude-option-2843'
Browse files Browse the repository at this point in the history
Fixes #2843
  • Loading branch information
arantius committed Jul 2, 2018
2 parents 88cb9bc + 2cddee9 commit 5ea7746
Show file tree
Hide file tree
Showing 10 changed files with 324 additions and 96 deletions.
12 changes: 12 additions & 0 deletions _locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@
"enabled": {
"message": "Enabled"
},
"Exclude": {
"message": "Exclude"
},
"extDesc": {
"message": "A User Script manager for Firefox."
},
Expand All @@ -78,6 +81,12 @@
"get_user_scripts": {
"message": "Get user scripts"
},
"global_excludes": {
"message": "Global Excludes"
},
"global_excludes_explain": {
"message": "One @exclude pattern per line. No user scripts will run here."
},
"gm_notif_text_must_be_string": {
"message": "GM.notification: \"text\" must be a string"
},
Expand Down Expand Up @@ -109,6 +118,9 @@
"greasemonkey_is_disabled": {
"message": "Greasemonkey is disabled"
},
"greasemonkey_options": {
"message": "Greasemonkey Options"
},
"greasemonkey_user_script_editor": {
"message": "Greasemonkey User Script Editor"
},
Expand Down
24 changes: 20 additions & 4 deletions doc/Messages.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,27 +68,27 @@ Data:
* `value` The new value to store.

# EnabledChanged
Sent by: `bg/is-enabled.js`.
Sent by: `bg/options.js`.

Sent whenever the global enabled status changes.

* `enabled` boolean, the new status (true = enabled, false = disabled).

# EnabledQuery
Received by: `bg/is-enabled.js`.
Received by: `bg/options.js`.

Send with no data, responds with a boolean: the new status
(true = enabled, false = disabled).

# EnabledSet
Received by: `bg/is-enabled.js`.
Received by: `bg/options.js`.

Send this to set the global enabled status.

* `enabled` boolean, the new status (true = enabled, false = disabled).

# EnabledToggle
Received by: `bg/is-enabled.js`.
Received by: `bg/options.js`.

Send this to toggle the global enabled status. No data.

Expand All @@ -109,6 +109,22 @@ Response data:

* An array of `.details` objects from installed `RunnableUserScript`s.

# OptionsLoad
Sent by: `browser/monkey-menu.js`
Received by: `bg/options.js`

Returns previously saved options data. Result is the same format as `OptionsSave`'s request.

* `excludes` A string, one `@exclude` pattern per line.

# OptionsSave
Sent by: `browser/monkey-menu.js`
Received by: `bg/options.js`

Passes the user's option values from content to background for persistence. Request data:

* `excludes` A string, one `@exclude` pattern per line.

# UserScriptGet
Sent by: `content/edit-user-script.js`

Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@
"/src/bg/api-provider-source.js",
"/src/bg/execute.js",
"/src/bg/export-db.js",
"/src/bg/is-enabled.js",
"/src/bg/on-message.js",
"/src/bg/on-user-script-notification.js",
"/src/bg/on-user-script-open-in-tab.js",
"/src/bg/on-user-script-xhr.js",
"/src/bg/options.js",
"/src/bg/user-script-detect.js",
"/src/bg/user-script-registry.js",
"/src/bg/value-store.js",
Expand Down
57 changes: 44 additions & 13 deletions src/bg/is-enabled.js → src/bg/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,45 @@ of Greasemonkey.
// Private implementation.
(function() {

let isEnabled = true;
let gIsEnabled = true;
chrome.storage.local.get('globalEnabled', v => {
isEnabled = v['globalEnabled'];
if ('undefined' == typeof isEnabled) isEnabled = true;
gIsEnabled = v['globalEnabled'];
if ('undefined' == typeof gIsEnabled) gIsEnabled = true;
setIcon();
});

let gGlobalExcludes = [];
chrome.storage.local.get('globalExcludes', v => {
let str = v['globalExcludes'];
if ('undefined' != typeof str) {
gGlobalExcludes = str.split('\n');
}
});


function getGlobalEnabled() {
return !!isEnabled;
return !!gIsEnabled;
}
window.getGlobalEnabled = getGlobalEnabled;


function getGlobalExcludes() {
return gGlobalExcludes.slice();
}
window.getGlobalExcludes = getGlobalExcludes;


function onEnabledQuery(message, sender, sendResponse) {
sendResponse(isEnabled);
sendResponse(gIsEnabled);
}
window.onEnabledQuery = onEnabledQuery;


function setGlobalEnabled(enabled) {
isEnabled = !!enabled;
gIsEnabled = !!enabled;
chrome.runtime.sendMessage({
'name': 'EnabledChanged',
'enabled': isEnabled,
'enabled': gIsEnabled,
}, logUnhandledError);
setIcon();
chrome.storage.local.set({'globalEnabled': enabled});
Expand All @@ -50,7 +64,7 @@ function setIcon() {
return;
}
let iconPath = chrome.extension.getURL('skin/icon.svg');
if (isEnabled) {
if (gIsEnabled) {
chrome.browserAction.setIcon({'path': iconPath});
} else {
let img = document.createElement('img');
Expand All @@ -69,17 +83,34 @@ function setIcon() {


function toggleGlobalEnabled() {
setGlobalEnabled(!isEnabled);
setGlobalEnabled(!gIsEnabled);
}
window.toggleGlobalEnabled = toggleGlobalEnabled;

/*****************************************************************************/

function onEnabledToggle(message, sender, sendResponse) {
try {
toggleGlobalEnabled();
sendResponse(isEnabled);
} catch (e) { console.error(e); }
toggleGlobalEnabled();
sendResponse(gIsEnabled);
}
window.onEnabledToggle = onEnabledToggle;


function onOptionsLoad(message, sender, sendResponse) {
let options = {
'excludes': gGlobalExcludes.join('\n'),
};
sendResponse(options);
}
window.onOptionsLoad = onOptionsLoad;


function onOptionsSave(message, sender, sendResponse) {
chrome.storage.local.set(
{'globalExcludes': message.excludes},
logUnhandledError);
gGlobalExcludes = message.excludes.split('\n');
}
window.onOptionsSave = onOptionsSave;

})();
98 changes: 69 additions & 29 deletions src/browser/monkey-menu.css
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ body#rendering { display: none; }


#script-list-scroll {
max-height: 380px;
max-height: 347px;
overflow-y: auto;
}

Expand All @@ -34,13 +34,50 @@ section {
width: 100vw;
}

section.user-script {
/* Hide non-main sections by default. */
section.options,
section.user-script
{
position: absolute;
top: 0;
left: 100vw;
}

body#user-script section { margin-left: -100vw; }
/* Slide the main menu away when it's non-active. */
section.main-menu
{ margin-left: -100vw; }
body#main-menu section.main-menu
{ margin-left: 0; }

/* Slide the other menu in when it's active. */
body#options section.options,
body#user-script section.user-script
{ margin-left: -100vw; }


section header {
color: -moz-fieldText;
overflow-x: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}

section menuitem.go-back {
box-sizing: content-box;
color: inherit;
display: inline-block;
height: 16px;
margin: 4px 4px 0 4px;
padding: 8px;
vertical-align: -10px; /* Relative to text, after padding. */
width: 16px;
}
section menuitem.go-back:hover {
background-color: var(--focus-color);
}
section menuitem.go-back::before {
content: url(/skin/back.svg);
}

/********************************** MENUS ************************************/

Expand Down Expand Up @@ -99,32 +136,6 @@ menu heading {

/***************************** SCRIPT DETAIL *********************************/

menuitem#back {
box-sizing: content-box;
color: inherit;
display: inline-block;
height: 16px;
margin: 4px 4px 0 4px;
padding: 8px;
vertical-align: -10px; /* Relative to text, after padding. */
width: 16px;
}
menuitem#back:hover {
background-color: var(--focus-color);
}
menuitem#back::before {
content: url(/skin/back.svg);
}


section header {
color: -moz-fieldText;
overflow-x: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}


section.user-script p {
margin: 0;
padding: 4px 12px 4px 10px;
Expand All @@ -140,3 +151,32 @@ section.user-script {
section.user-script menu {
overflow-y: auto;
}

/******************************** OPTIONS ************************************/

section.options p {
margin: 0;
padding: 4px 12px 4px 10px;
}

section.options .explain a {
color: black;
float: right;
}

section.options textarea {
font-family: monospace;
font-size: 90%;
white-space: pre;
}

section.options #add-exclude-current {
cursor: pointer;
display: block;
margin-top: 4px;
padding: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
width: 90vw;
}

0 comments on commit 5ea7746

Please sign in to comment.