Adaptations pour chrome
This commit is contained in:
parent
148fffd753
commit
8ae749fec5
92
inject.js
92
inject.js
@ -1,47 +1,47 @@
|
||||
function createLink(name, oldURL, newURL) {
|
||||
let e = document.createElement("a");
|
||||
e.className = "_wims_tester_link";
|
||||
e.innerText = "[" + browser.i18n.getMessage("openOnServer") + `'${name}']`;
|
||||
let link = new URL(newURL);
|
||||
link.search = new URL(oldURL).search;
|
||||
e.href = link.toString();
|
||||
e.target = "_blank";
|
||||
return e;
|
||||
}
|
||||
|
||||
function updateLink(e, name, url) {
|
||||
e.innerText = "[" + browser.i18n.getMessage("openOnServer") + `'${name}']`;
|
||||
let link = new URL(url);
|
||||
link.search = new URL(e.href).search;
|
||||
e.href = link.toString();
|
||||
}
|
||||
|
||||
async function load() {
|
||||
let serversList = await fetch(browser.runtime.getURL("servers.json")).then((response) => response.json()).then((data) => data["servers"]);
|
||||
let preferredServer = await browser.storage.sync.get('preferredServer').then(item => item.preferredServer);
|
||||
if (typeof preferredServer === "undefined" || !preferredServer.hasOwnProperty("url")) preferredServer = serversList[0];
|
||||
|
||||
let list = document.getElementsByClassName("wims_exo_item");
|
||||
for (let item of list) item.firstElementChild.after(createLink(preferredServer.name, item.firstElementChild.href, preferredServer.url));
|
||||
|
||||
list = document.querySelectorAll('a[target="wims_exo"]');
|
||||
for (let item of list) item.after(createLink(preferredServer.name, item.href, preferredServer.url));
|
||||
|
||||
list = document.querySelectorAll('ul[class="wims_home_result_list"] > li');
|
||||
for (let item of list) item.firstElementChild.after(createLink(preferredServer.name, item.firstElementChild.href, preferredServer.url));
|
||||
}
|
||||
|
||||
let style = document.createElement('style');
|
||||
style.textContent = "._wims_tester_link::before { content: ' '; } ._wims_tester_link { font-size: small; color: black; }";
|
||||
document.head.append(style);
|
||||
|
||||
load();
|
||||
|
||||
browser.storage.sync.onChanged.addListener((changes) => {
|
||||
const changedItems = Object.keys(changes);
|
||||
for (const item of changedItems) {
|
||||
if (item == "preferredServer") {
|
||||
document.querySelectorAll('a[class="_wims_tester_link"]').forEach(e => updateLink(e, changes[item].newValue.name, changes[item].newValue.url));
|
||||
}
|
||||
}
|
||||
function createLink(name, oldURL, newURL) {
|
||||
let e = document.createElement("a");
|
||||
e.className = "_wims_tester_link";
|
||||
e.innerText = "[" + chrome.i18n.getMessage("openOnServer") + `'${name}']`;
|
||||
let link = new URL(newURL);
|
||||
link.search = new URL(oldURL).search;
|
||||
e.href = link.toString();
|
||||
e.target = "_blank";
|
||||
return e;
|
||||
}
|
||||
|
||||
function updateLink(e, name, url) {
|
||||
e.innerText = "[" + chrome.i18n.getMessage("openOnServer") + `'${name}']`;
|
||||
let link = new URL(url);
|
||||
link.search = new URL(e.href).search;
|
||||
e.href = link.toString();
|
||||
}
|
||||
|
||||
async function load() {
|
||||
let serversList = await fetch(chrome.runtime.getURL("servers.json")).then((response) => response.json()).then((data) => data["servers"]);
|
||||
let preferredServer = await chrome.storage.sync.get('preferredServer').then(item => item.preferredServer);
|
||||
if (typeof preferredServer === "undefined" || !preferredServer.hasOwnProperty("url")) preferredServer = serversList[0];
|
||||
|
||||
let list = document.getElementsByClassName("wims_exo_item");
|
||||
for (let item of list) item.firstElementChild.after(createLink(preferredServer.name, item.firstElementChild.href, preferredServer.url));
|
||||
|
||||
list = document.querySelectorAll('a[target="wims_exo"]');
|
||||
for (let item of list) item.after(createLink(preferredServer.name, item.href, preferredServer.url));
|
||||
|
||||
list = document.querySelectorAll('ul[class="wims_home_result_list"] > li');
|
||||
for (let item of list) item.firstElementChild.after(createLink(preferredServer.name, item.firstElementChild.href, preferredServer.url));
|
||||
}
|
||||
|
||||
let style = document.createElement('style');
|
||||
style.textContent = "._wims_tester_link::before { content: ' '; } ._wims_tester_link { font-size: small; color: black; }";
|
||||
document.head.append(style);
|
||||
|
||||
load();
|
||||
|
||||
chrome.storage.sync.onChanged.addListener((changes) => {
|
||||
const changedItems = Object.keys(changes);
|
||||
for (const item of changedItems) {
|
||||
if (item == "preferredServer") {
|
||||
document.querySelectorAll('a[class="_wims_tester_link"]').forEach(e => updateLink(e, changes[item].newValue.name, changes[item].newValue.url));
|
||||
}
|
||||
}
|
||||
});
|
121
manifest.json
121
manifest.json
@ -1,61 +1,62 @@
|
||||
{
|
||||
"manifest_version": 2,
|
||||
"name": "WIMS Tester",
|
||||
"author": "Lyanis Souidi",
|
||||
"version": "1.0",
|
||||
"browser_specific_settings": {
|
||||
"gecko": {
|
||||
"id": "wims-tester@lyanis.sh"
|
||||
}
|
||||
},
|
||||
"description": "__MSG_extensionDescription__",
|
||||
"homepage_url": "https://github.com/lyanissouidi/wims-tester",
|
||||
"default_locale": "en",
|
||||
"browser_action": {
|
||||
"default_title": "WIMS Tester",
|
||||
"default_popup": "index.html",
|
||||
"browser_style": true,
|
||||
"default_icon": {
|
||||
"16": "icons/16-light.png",
|
||||
"32": "icons/32-light.png",
|
||||
"48": "icons/48-light.png",
|
||||
"96": "icons/96-light.png",
|
||||
"128": "icons/128-light.png"
|
||||
},
|
||||
"theme_icons": [{
|
||||
"light": "icons/16-light.png",
|
||||
"dark": "icons/16-dark.png",
|
||||
"size": 16
|
||||
}, {
|
||||
"light": "icons/32-light.png",
|
||||
"dark": "icons/32-dark.png",
|
||||
"size": 32
|
||||
}, {
|
||||
"light": "icons/48-light.png",
|
||||
"dark": "icons/48-dark.png",
|
||||
"size": 48
|
||||
}, {
|
||||
"light": "icons/96-light.png",
|
||||
"dark": "icons/96-dark.png",
|
||||
"size": 96
|
||||
}, {
|
||||
"light": "icons/128-light.png",
|
||||
"dark": "icons/128-dark.png",
|
||||
"size": 128
|
||||
}]
|
||||
},
|
||||
"content_scripts": [
|
||||
{
|
||||
"matches": ["*://*/*wims.cgi*"],
|
||||
"js": ["inject.js"]
|
||||
}
|
||||
],
|
||||
"permissions": ["tabs", "storage"],
|
||||
"icons": {
|
||||
"16": "icons/16-light.png",
|
||||
"32": "icons/32-light.png",
|
||||
"48": "icons/48-light.png",
|
||||
"96": "icons/96-light.png",
|
||||
"128": "icons/128-light.png"
|
||||
}
|
||||
{
|
||||
"manifest_version": 3,
|
||||
"name": "WIMS Tester",
|
||||
"author": "Lyanis Souidi",
|
||||
"version": "1.1",
|
||||
"description": "__MSG_extensionDescription__",
|
||||
"homepage_url": "https://github.com/lyanissouidi/wims-tester/tree/chrome",
|
||||
"default_locale": "en",
|
||||
"action": {
|
||||
"default_title": "WIMS Tester",
|
||||
"default_popup": "index.html",
|
||||
"browser_style": true,
|
||||
"default_icon": {
|
||||
"16": "icons/16-light.png",
|
||||
"32": "icons/32-light.png",
|
||||
"48": "icons/48-light.png",
|
||||
"96": "icons/96-light.png",
|
||||
"128": "icons/128-light.png"
|
||||
},
|
||||
"theme_icons": [{
|
||||
"light": "icons/16-light.png",
|
||||
"dark": "icons/16-dark.png",
|
||||
"size": 16
|
||||
}, {
|
||||
"light": "icons/32-light.png",
|
||||
"dark": "icons/32-dark.png",
|
||||
"size": 32
|
||||
}, {
|
||||
"light": "icons/48-light.png",
|
||||
"dark": "icons/48-dark.png",
|
||||
"size": 48
|
||||
}, {
|
||||
"light": "icons/96-light.png",
|
||||
"dark": "icons/96-dark.png",
|
||||
"size": 96
|
||||
}, {
|
||||
"light": "icons/128-light.png",
|
||||
"dark": "icons/128-dark.png",
|
||||
"size": 128
|
||||
}]
|
||||
},
|
||||
"content_scripts": [
|
||||
{
|
||||
"matches": ["*://*/*wims.cgi*"],
|
||||
"js": ["inject.js"]
|
||||
}
|
||||
],
|
||||
"web_accessible_resources": [
|
||||
{
|
||||
"resources": ["servers.json"],
|
||||
"matches": ["<all_urls>"]
|
||||
}
|
||||
],
|
||||
"permissions": ["tabs", "storage"],
|
||||
"icons": {
|
||||
"16": "icons/16-light.png",
|
||||
"32": "icons/32-light.png",
|
||||
"48": "icons/48-light.png",
|
||||
"96": "icons/96-light.png",
|
||||
"128": "icons/128-light.png"
|
||||
}
|
||||
}
|
79
script.js
79
script.js
@ -1,37 +1,42 @@
|
||||
document.getElementsByTagName("legend")[0].innerText = browser.i18n.getMessage("serverSelection");
|
||||
async function updateLink(name, url) {
|
||||
let link = new URL(url);
|
||||
let tabURL = await browser.tabs.query({currentWindow: true, active: true}).then(tabs => tabs[0].url);
|
||||
link.search = new URL(tabURL).search;
|
||||
let a = document.getElementsByTagName("a")[0];
|
||||
a.href = link.toString();
|
||||
a.innerText = browser.i18n.getMessage("openCurrentPageOnServer") + `'${name}'`;
|
||||
}
|
||||
|
||||
async function load(qualifiedName, value) {
|
||||
let serversList = await fetch(browser.runtime.getURL("servers.json")).then((response) => response.json()).then((data) => data["servers"]);
|
||||
let preferredServer = await browser.storage.sync.get('preferredServer').then(item => item.preferredServer);
|
||||
if (typeof preferredServer === "undefined" || !preferredServer.hasOwnProperty("url")) preferredServer = serversList[0];
|
||||
for (let i = 0; i < serversList.length; i++) {
|
||||
let div = document.createElement("div");
|
||||
let input = document.createElement("input");
|
||||
input.type = "radio";
|
||||
input.id = serversList[i].url;
|
||||
input.name = "server";
|
||||
input.value = serversList[i].name;
|
||||
if (preferredServer.url === serversList[i].url) input.checked = true;
|
||||
input.addEventListener("click", saveServer);
|
||||
div.appendChild(input);
|
||||
let label = document.createElement("label");
|
||||
label.for = serversList[i].name;
|
||||
label.innerText = serversList[i].name;
|
||||
div.appendChild(label);
|
||||
document.getElementById("servers").appendChild(div);
|
||||
}
|
||||
updateLink(preferredServer.name, preferredServer.url);
|
||||
}
|
||||
load();
|
||||
function saveServer(e) {
|
||||
browser.storage.sync.set({ preferredServer: { name: e.target.value, url: e.target.id } });
|
||||
updateLink(e.target.value, e.target.id);
|
||||
}
|
||||
document.getElementsByTagName("legend")[0].innerText = chrome.i18n.getMessage("serverSelection");
|
||||
async function updateLink(name, url) {
|
||||
let tabURL = await chrome.tabs.query({currentWindow: true, active: true}).then(tabs => tabs[0].url);
|
||||
if (tabURL.includes("wims.cgi") && !tabURL.includes(url)) {
|
||||
let link = new URL(url);
|
||||
link.search = new URL(tabURL).search;
|
||||
let a = document.getElementsByTagName("a")[0];
|
||||
a.href = link.toString();
|
||||
a.innerText = chrome.i18n.getMessage("openCurrentPageOnServer") + `'${name}'`;
|
||||
}
|
||||
}
|
||||
|
||||
async function load() {
|
||||
let serversList = await fetch(chrome.runtime.getURL("servers.json")).then((response) => response.json()).then((data) => data["servers"]);
|
||||
let preferredServer = await chrome.storage.sync.get('preferredServer').then(item => item.preferredServer);
|
||||
let tabURL = await chrome.tabs.query({currentWindow: true, active: true}).then(tabs => tabs[0].url);
|
||||
if (typeof preferredServer === "undefined" || !preferredServer.hasOwnProperty("url")) preferredServer = serversList[0];
|
||||
for (let i = 0; i < serversList.length; i++) {
|
||||
if (!tabURL.includes(serversList[i].url)) {
|
||||
let div = document.createElement("div");
|
||||
let input = document.createElement("input");
|
||||
input.type = "radio";
|
||||
input.id = serversList[i].url;
|
||||
input.name = "server";
|
||||
input.value = serversList[i].name;
|
||||
if (preferredServer.url === serversList[i].url) input.checked = true;
|
||||
input.addEventListener("click", saveServer);
|
||||
div.appendChild(input);
|
||||
let label = document.createElement("label");
|
||||
label.for = serversList[i].name;
|
||||
label.innerText = serversList[i].name;
|
||||
div.appendChild(label);
|
||||
document.getElementById("servers").appendChild(div);
|
||||
}
|
||||
}
|
||||
updateLink(preferredServer.name, preferredServer.url);
|
||||
}
|
||||
load();
|
||||
function saveServer(e) {
|
||||
chrome.storage.sync.set({ preferredServer: { name: e.target.value, url: e.target.id } });
|
||||
updateLink(e.target.value, e.target.id);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user