Change hosts delimiter to new line
Added options page accessible via action
This commit is contained in:
parent
1ad02924ba
commit
014d3837ee
@ -40,11 +40,11 @@ Recently chrome disallowed to install packed `crx` extension that are not listed
|
||||
- On Firefox: enter `about:debugging#/runtime/this-firefox` into the address bar
|
||||
- In the Extension page find `conventional comments button` and hit the reload button
|
||||
|
||||
## How to run it on a self-hosted instance
|
||||
## How to enable it on a self-hosted instance
|
||||
|
||||
- Open manifest.json
|
||||
- Add your domain to `permissions` and `content_scripts -> matches`
|
||||
- Open the browser and install or update the extension
|
||||
- Open the extension options
|
||||
- Add your domain as a new line in the "Enabled Hosts" field
|
||||
- Click Save
|
||||
|
||||
## Credits
|
||||
|
||||
|
@ -10,7 +10,10 @@
|
||||
"128": "icons/icon128.png"
|
||||
},
|
||||
"default_locale": "en",
|
||||
"options_page": "src/options.html",
|
||||
"action": {},
|
||||
"options_ui": {
|
||||
"page": "src/options.html"
|
||||
},
|
||||
"permissions": [
|
||||
"activeTab",
|
||||
"storage",
|
||||
|
@ -1,12 +1,11 @@
|
||||
const scriptId = "conventional-comments-button";
|
||||
const defaultHost = 'https://gitlab.com';
|
||||
|
||||
async function registerContentScripts(hosts)
|
||||
{
|
||||
hosts = hosts.split(',');
|
||||
|
||||
async function registerContentScripts(hosts) {
|
||||
hosts = hosts.split('\n');
|
||||
|
||||
for (var index in hosts) {
|
||||
hosts[index] += "/*";
|
||||
hosts[index] = hosts[index].trim() + "/*";
|
||||
}
|
||||
|
||||
await chrome.scripting.registerContentScripts([{
|
||||
@ -18,7 +17,11 @@ async function registerContentScripts(hosts)
|
||||
}]);
|
||||
}
|
||||
|
||||
chrome.storage.sync.get({hosts: defaultHost}, async function(result) {
|
||||
chrome.action.onClicked.addListener(() => {
|
||||
chrome.runtime.openOptionsPage();
|
||||
})
|
||||
|
||||
chrome.storage.sync.get({ hosts: defaultHost }, async function (result) {
|
||||
console.log('Hosts is currently ', result);
|
||||
|
||||
var hosts = result.hosts;
|
||||
@ -29,10 +32,10 @@ chrome.storage.sync.get({hosts: defaultHost}, async function(result) {
|
||||
});
|
||||
|
||||
chrome.storage.onChanged.addListener(async (changes, areaName) => {
|
||||
if (changes['hosts']) {
|
||||
await chrome.scripting.unregisterContentScripts({ids: [scriptId]});
|
||||
console.log("Setting new hosts to " + changes['hosts']['newValue']);
|
||||
await registerContentScripts(changes['hosts']['newValue']);
|
||||
}
|
||||
if (changes['hosts']) {
|
||||
await chrome.scripting.unregisterContentScripts({ ids: [scriptId] });
|
||||
console.log("Setting new hosts to " + changes['hosts']['newValue']);
|
||||
await registerContentScripts(changes['hosts']['newValue']);
|
||||
}
|
||||
)
|
||||
}
|
||||
)
|
||||
|
@ -4,13 +4,13 @@
|
||||
<body>
|
||||
|
||||
<label>
|
||||
Hosts:
|
||||
Enabled Hosts (one per line):
|
||||
</label>
|
||||
<input type="text" id="hosts">
|
||||
<textarea id="hosts" rows="5" cols="49"></textarea>
|
||||
|
||||
<div id="status"></div>
|
||||
<button id="save">Save</button>
|
||||
|
||||
<script src="options.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
Loading…
Reference in New Issue
Block a user