Skip to content

Commit 5fec6d6

Browse files
committed
✨ Init
0 parents  commit 5fec6d6

File tree

9 files changed

+1932
-0
lines changed

9 files changed

+1932
-0
lines changed

.eslintrc.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module.exports = {
2+
extends: [
3+
'@methodgrab/standard',
4+
'@methodgrab/standard/browser',
5+
'@methodgrab/standard/esnext',
6+
],
7+
8+
env: {},
9+
10+
globals: {},
11+
12+
rules: {
13+
'no-param-reassign' : 'off',
14+
'no-unused-expressions' : [ 'warn', { allowShortCircuit: true, allowTernary: true } ],
15+
},
16+
};

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
npm-debug.log

LICENSE.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
ISC License
2+
3+
Copyright (c) 2016, Nick (@methodgrab)
4+
5+
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
6+
7+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

README.md

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Custom New Tab Page
2+
> Specify a custom URL to show when opening new tabs, _without changing the address bar_.
3+
4+
5+
## Usage
6+
To set your custom new tab url:
7+
- Open `about:addons`
8+
- Select `Extensions`
9+
- Select the `Custom New Tab Page` extension → `Options`
10+
- Enter your URL in the `New Tab URL` box
11+
- Done!
12+
13+
14+
## Development
15+
16+
Testing unsigned extensions only works with [non-release](https://developer.mozilla.org/en-US/Add-ons/SDK/Tools/jpm#Install_a_different_version_of_Firefox) [builds](https://wiki.mozilla.org/Add-ons/Extension_Signing). To install the unsigned extension:
17+
- Open Firefox Developer Edition
18+
- Install the [Extension Auto-Installer](https://addons.mozilla.org/en-US/firefox/addon/autoinstaller) add-on
19+
- Open `about:config`
20+
- set `xpinstall.signatures.required` to `false`
21+
- Close Firefox Developer Edition
22+
- `npm run start` to load Firefox Developer Edition with the extension installed
23+
- `npm run watch` to watch for changes and [reload the extension automatically](https://developer.mozilla.org/en-US/Add-ons/SDK/Tools/jpm#Developing_without_browser_restarts)
24+
25+
_NB: These `npm` commands assume you're on Windows with Firefox Developer Edition installed, modify the paths as needed._
26+
27+
28+
### Logging
29+
To show [log messages](https://developer.mozilla.org/en-US/Add-ons/SDK/Tools/console#Logging_Levels) during development:
30+
- Open `about:config`
31+
- Create a new string value called `[email protected]` with a value of `all`
32+
33+
34+
## Release Process
35+
36+
After making changes to the extension, do the following to publish a new version:
37+
1. `npm run package` to bundle the `xpi` file
38+
1. Upload the generated `xpi` to https://addons.mozilla.org/en-US/developers/addons

data/app.css

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
.cntp-has-loaded *,
2+
.cntp-has-loaded *:before,
3+
.cntp-has-loaded *:after {
4+
margin: 0;
5+
padding: 0;
6+
}
7+
8+
.cntp-has-loaded body {
9+
display: block;
10+
position: relative;
11+
overflow: hidden;
12+
width: 100vw;
13+
height: 100vh;
14+
}
15+
16+
.cntp-has-loaded .cntp__iframe {
17+
position: absolute;
18+
top: 0;
19+
left: 0;
20+
width: 100vw;
21+
height: 100vh;
22+
border: 0;
23+
}

data/app.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
const showCustomPage = customNewTabUrl => {
2+
console.debug( '[showCustomPage] init', { customNewTabUrl } );
3+
4+
// no tab URL set, do nothing
5+
if ( !customNewTabUrl || !customNewTabUrl.length ) {
6+
console.debug( '[showCustomPage] no tab url set' );
7+
return false;
8+
}
9+
10+
document.querySelector( 'html' ).classList.add( 'cntp-has-loaded' );
11+
12+
const content = `<iframe class="cntp__iframe" src="${customNewTabUrl}"></iframe>`;
13+
document.body.innerHTML = content;
14+
15+
return true;
16+
};
17+
18+
self.port.on( 'showCustomPage', showCustomPage );

index.js

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
const self = require( 'sdk/self' );
2+
const pageMod = require( 'sdk/page-mod' );
3+
const tabs = require( 'sdk/tabs' );
4+
const sp = require( 'sdk/simple-prefs' );
5+
6+
const NEW_TAB_URL = 'about:newtab';
7+
8+
9+
pageMod.PageMod({
10+
include : [ NEW_TAB_URL ],
11+
contentScriptFile : './app.js',
12+
contentStyleFile : './app.css',
13+
onAttach( worker ) {
14+
worker.port.emit( 'showCustomPage', sp.prefs.customNewTabUrl );
15+
},
16+
});
17+
18+
19+
// Listen for tab openings
20+
tabs.on( 'open', function onOpen( tab ) {
21+
if ( tab.url === NEW_TAB_URL ) {
22+
// redirect so pageMod can intercept
23+
tab.url = NEW_TAB_URL;
24+
}
25+
});

package.json

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"title": "Custom New Tab Page",
3+
"name": "custom-new-tab-page",
4+
5+
"version": "0.1.0",
6+
"description": "Specify a custom URL to show when opening new tabs, without changing the address bar",
7+
"homepage": "https://github.com/methodgrab/firefox-custom-new-tab-page",
8+
"main": "index.js",
9+
"author": "MethodGrab",
10+
"engines": {
11+
"firefox": ">=38.0a1"
12+
},
13+
"license": "ISC",
14+
"keywords": [
15+
"custom",
16+
"new",
17+
"tab",
18+
"page",
19+
"url"
20+
],
21+
"scripts": {
22+
"test": "npm run lint",
23+
"lint": "eslint **/*.js",
24+
"start": "jpm run --binary \"C:\\Program Files (x86)\\Firefox Developer Edition\\firefox.exe\" -p dev-edition-default",
25+
"watch": "jpm watchpost --post-url http://localhost:8888/",
26+
"package": "jpm xpi"
27+
},
28+
"devDependencies": {
29+
"@methodgrab/eslint-config-standard": "^0.10.0",
30+
"eslint": "^3.8.0",
31+
"jpm": "^1.2.2"
32+
},
33+
"preferences": [
34+
{
35+
"name": "customNewTabUrl",
36+
"title": "New Tab URL",
37+
"description": "The URL to show when a new tab is opened",
38+
"type": "string",
39+
"value": ""
40+
}
41+
]
42+
}

0 commit comments

Comments
 (0)