Adaptations pour chrome

This commit is contained in:
Lyanis SOUIDI 2023-03-08 15:31:01 +01:00
parent 148fffd753
commit 8ae749fec5
3 changed files with 149 additions and 143 deletions

View File

@ -1,7 +1,7 @@
function createLink(name, oldURL, newURL) {
let e = document.createElement("a");
e.className = "_wims_tester_link";
e.innerText = "[" + browser.i18n.getMessage("openOnServer") + `'${name}']`;
e.innerText = "[" + chrome.i18n.getMessage("openOnServer") + `'${name}']`;
let link = new URL(newURL);
link.search = new URL(oldURL).search;
e.href = link.toString();
@ -10,15 +10,15 @@ function createLink(name, oldURL, newURL) {
}
function updateLink(e, name, url) {
e.innerText = "[" + browser.i18n.getMessage("openOnServer") + `'${name}']`;
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(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);
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");
@ -37,7 +37,7 @@ document.head.append(style);
load();
browser.storage.sync.onChanged.addListener((changes) => {
chrome.storage.sync.onChanged.addListener((changes) => {
const changedItems = Object.keys(changes);
for (const item of changedItems) {
if (item == "preferredServer") {

View File

@ -1,17 +1,12 @@
{
"manifest_version": 2,
"manifest_version": 3,
"name": "WIMS Tester",
"author": "Lyanis Souidi",
"version": "1.0",
"browser_specific_settings": {
"gecko": {
"id": "wims-tester@lyanis.sh"
}
},
"version": "1.1",
"description": "__MSG_extensionDescription__",
"homepage_url": "https://github.com/lyanissouidi/wims-tester",
"homepage_url": "https://github.com/lyanissouidi/wims-tester/tree/chrome",
"default_locale": "en",
"browser_action": {
"action": {
"default_title": "WIMS Tester",
"default_popup": "index.html",
"browser_style": true,
@ -50,6 +45,12 @@
"js": ["inject.js"]
}
],
"web_accessible_resources": [
{
"resources": ["servers.json"],
"matches": ["<all_urls>"]
}
],
"permissions": ["tabs", "storage"],
"icons": {
"16": "icons/16-light.png",

View File

@ -1,37 +1,42 @@
document.getElementsByTagName("legend")[0].innerText = browser.i18n.getMessage("serverSelection");
document.getElementsByTagName("legend")[0].innerText = chrome.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}'`;
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(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);
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++) {
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);
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) {
browser.storage.sync.set({ preferredServer: { name: e.target.value, url: e.target.id } });
chrome.storage.sync.set({ preferredServer: { name: e.target.value, url: e.target.id } });
updateLink(e.target.value, e.target.id);
}