Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
tor-browser-settings
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Thomas Rientjes
tor-browser-settings
Commits
9dcd8bbc
Commit
9dcd8bbc
authored
8 years ago
by
Thomas Rientjes
Browse files
Options
Downloads
Patches
Plain Diff
Refactor existing code
parent
5a7d92e2
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
data/content-scripts/settings.js
+29
-9
29 additions, 9 deletions
data/content-scripts/settings.js
src/main.js
+50
-16
50 additions, 16 deletions
src/main.js
with
79 additions
and
25 deletions
data/content-scripts/settings.js
+
29
−
9
View file @
9dcd8bbc
/**
* Application settings content script.
*
* @module content-scripts/settings
*/
'
use strict
'
;
/**
/**
* Fires once the content script worker is initialized.
* Fires once the content script worker is initialized.
*
*
* @event worker:initialized
* @param {Object} initialState The initial state of the settings module.
* @param {Object} initialState The initial state of the settings module.
* @listens main/worker:initialized
*/
*/
self
.
port
.
once
(
'
worker:initialized
'
,
function
(
initialState
)
{
self
.
port
.
once
(
'
worker:initialized
'
,
function
(
initialState
)
{
applyL10n
(
initialState
.
l10n
);
applyL10n
(
initialState
.
l10n
);
});
});
/**
* Fires once a preference has been fetched.
*
* @param {Object} preference The externally fetched preference.
* @listens main/preference:fetched
*/
self
.
port
.
on
(
'
preference:fetched
'
,
function
()
{
self
.
port
.
on
(
'
preference:fetched
'
,
function
()
{
// TODO Re-render the user interface.
// TODO Re-render the user interface.
});
});
...
@@ -18,8 +31,8 @@ self.port.on('preference:fetched', function () {
...
@@ -18,8 +31,8 @@ self.port.on('preference:fetched', function () {
* Applies a given localization to marked document elements.
* Applies a given localization to marked document elements.
* https://bugzilla.mozilla.org/show_bug.cgi?id=787351
* https://bugzilla.mozilla.org/show_bug.cgi?id=787351
*
*
* @private
* @param {Object} l10n A localization object.
* @param {Object} l10n A localization object.
* @private
*/
*/
function
applyL10n
(
l10n
)
{
function
applyL10n
(
l10n
)
{
...
@@ -35,15 +48,22 @@ function applyL10n (l10n) {
...
@@ -35,15 +48,22 @@ function applyL10n (l10n) {
});
});
}
}
/**
* Fetch preference event emitter.
*
* @event preference:fetch
* @property {String} preferenceKey The key of the requested preference.
*/
function
fetchPreference
(
preferenceKey
)
{
function
fetchPreference
(
preferenceKey
)
{
self
.
port
.
emit
(
'
preference:fetch
'
,
preferenceKey
);
self
.
port
.
emit
(
'
preference:fetch
'
,
preferenceKey
);
}
}
/**
/**
* Emitters
* Preference changed event emitter.
*
* @event preference:changed
* @property {Object} preference The updated preference.
*/
*/
function
preferenceChanged
(
preference
)
{
self
.
port
.
emit
(
'
preference:changed
'
,
{
self
.
port
.
emit
(
'
preference:changed
'
,
preference
);
key
:
'
sliderPosition
'
,
}
value
:
2
});
This diff is collapsed.
Click to expand it.
src/main.js
+
50
−
16
View file @
9dcd8bbc
/**
/**
* Main
* Application entry point.
*
* @module main
*/
*/
'
use strict
'
;
'
use strict
'
;
/**
/**
* Imports
* Simplifies the process of obtaining browser service references.
*
* @var {Object} Services
*/
*/
var
{
Services
}
=
require
(
'
resource://gre/modules/Services.jsm
'
);
var
{
Services
}
=
require
(
'
resource://gre/modules/Services.jsm
'
);
/**
* Can be used to get localization entries by key name.
*
* @var {function} _
*/
var
_
=
require
(
'
sdk/l10n
'
).
get
;
var
_
=
require
(
'
sdk/l10n
'
).
get
;
var
pageMod
=
require
(
'
sdk/page-mod
'
);
var
self
=
require
(
"
sdk/self
"
);
/**
/**
* Constants
* Facilitates running scripts in the context of web pages.
*
* @var {Object} pageMod
*/
*/
var
pageMod
=
require
(
'
sdk/page-mod
'
);
const
BROWSER_NAME
=
'
Orfox
'
;
/**
* Provides access to extension metadata.
*
* @var {Object} self
*/
var
self
=
require
(
"
sdk/self
"
);
/**
/**
* Variables
* The browser's chrome window object.
*
* @var {Object} chromeWindow
*/
*/
var
chromeWindow
=
Services
.
wm
.
getMostRecentWindow
(
'
navigator:browser
'
);
var
browserWindow
=
Services
.
wm
.
getMostRecentWindow
(
'
navigator:browser
'
);
/**
var
browserWindowIdentifier
=
null
;
* Uniquely identifies the extension's chrome menu item.
*
* @var {Number} chomeMenuItemIdentifier
*/
var
chromeMenuItemIdentifier
=
null
;
/**
/**
* Public Functions
* The name of the target browser.
*
* @constant BROWSER_NAME
* @type {String}
* @default
*/
*/
const
BROWSER_NAME
=
'
Orfox
'
;
/**
* Executed as soon as the add-on is loaded.
*/
exports
.
main
=
function
()
{
exports
.
main
=
function
()
{
pageMod
.
PageMod
({
pageMod
.
PageMod
({
...
@@ -40,11 +69,12 @@ exports.main = function () {
...
@@ -40,11 +69,12 @@ exports.main = function () {
onAttach
:
startListening
onAttach
:
startListening
});
});
browserWindowIdentifier
=
browserWindow
.
NativeWindow
.
menu
.
add
({
// Add the extension's chrome menu item to the main browser menu.
chromeMenuItemIdentifier
=
chromeWindow
.
NativeWindow
.
menu
.
add
({
name
:
_
(
'
settings_label
'
,
BROWSER_NAME
),
name
:
_
(
'
settings_label
'
,
BROWSER_NAME
),
callback
:
function
()
{
callback
:
function
()
{
var
tabBrowser
=
browser
Window
.
BrowserApp
;
var
tabBrowser
=
chrome
Window
.
BrowserApp
;
tabBrowser
.
addTab
(
'
chrome://tor-browser-settings/content/settings.html
'
,
{
tabBrowser
.
addTab
(
'
chrome://tor-browser-settings/content/settings.html
'
,
{
selected
:
true
,
selected
:
true
,
...
@@ -55,16 +85,20 @@ exports.main = function () {
...
@@ -55,16 +85,20 @@ exports.main = function () {
});
});
};
};
/**
* Executed when the add-on is unloaded.
*/
exports
.
onUnload
=
function
()
{
exports
.
onUnload
=
function
()
{
// Clean up add-on state.
// Clean up add-on state.
browser
Window
.
NativeWindow
.
menu
.
remove
(
browserWindow
Identifier
);
chrome
Window
.
NativeWindow
.
menu
.
remove
(
chromeMenuItem
Identifier
);
};
};
/**
/**
* Private Functions
* Executed as soon as a content script has been attached to a page.
*
* @param {Object} worker Allows for direct communication with content scripts.
*/
*/
function
startListening
(
worker
)
{
function
startListening
(
worker
)
{
worker
.
port
.
emit
(
'
worker:initialized
'
,
{
worker
.
port
.
emit
(
'
worker:initialized
'
,
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment