Compare commits

...

3 commits
v1.0.0 ... main

Author SHA1 Message Date
a9419dc920
Update version 2023-06-02 23:23:34 +02:00
9d0e71eac7
fix copied text 2023-06-02 23:22:57 +02:00
28c1ebbacf
Add files via upload 2022-09-04 18:39:13 +02:00
3 changed files with 59 additions and 22 deletions

10
background.js Normal file
View file

@ -0,0 +1,10 @@
chrome.runtime.onInstalled.addListener(function() {
chrome.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) {
if(changeInfo.status == 'complete' && tab.url == 'https://www.dofusbook.net/fr/outils/atelier' && tab.status == 'complete'){
chrome.scripting.executeScript({
target: { tabId: tab.id },
files: ["dofusbook.atelier.copy.js"]
});
}
});
});

View file

@ -1,26 +1,44 @@
function waitResources() { function addCopyButtonAtelier() {
const buttonPropertiesConstants = {
"textButtonCopy": "copy",
"backgroundColorButtonCopy": "",
"textButtonCopied": "copied",
"backgroundColorButtonCopied": "#6dc700"
};
const itemCells = document.getElementsByClassName('cell'); const itemCells = document.getElementsByClassName('cell');
if(itemCells.length > 0){ if(itemCells.length > 0){
for(const itemCell of itemCells) { for(const itemCell of itemCells) {
const itemWrapper = itemCell.getElementsByClassName('wrapper').item(0); const itemWrapper = itemCell.getElementsByClassName('wrapper').item(0);
const itemName = itemWrapper.getElementsByClassName('label').item(0).innerHTML.slice(1, -1); const itemName = itemWrapper.getElementsByClassName('label').item(0).innerHTML;
let itemCopyButton = document.createElement("button"); if(itemWrapper.getElementsByClassName('copy-btn').length == 0){
itemCopyButton.innerHTML = "copy"; let itemCopyButton = document.createElement("button");
itemCopyButton.onclick = function(){ itemCopyButton.innerHTML = buttonPropertiesConstants.textButtonCopy;
navigator.clipboard.writeText(itemName).then(() => { itemCopyButton.setAttribute('class', 'copy-btn');
console.info(`${itemName} copied !`);
}, () => { itemCopyButton.onclick = function(){
console.error(`ERROR ${itemName} not copied !`); navigator.clipboard.writeText(itemName).then(() => {
}); console.info(`${itemName} copied !`);
}; itemCopyButton.innerHTML = buttonPropertiesConstants.textButtonCopied;
itemCopyButton.style.backgroundColor = buttonPropertiesConstants.backgroundColorButtonCopied;
setTimeout(function(){
itemCopyButton.innerHTML = buttonPropertiesConstants.textButtonCopy;
itemCopyButton.style.backgroundColor = buttonPropertiesConstants.backgroundColorButtonCopy;
}, 3000);
}, () => {
console.error(`ERROR ${itemName} not copied !`);
});
};
itemWrapper.appendChild(itemCopyButton); itemWrapper.appendChild(itemCopyButton);
} else { console.error("copy-btn already exist"); }
} }
} else { } else {
setTimeout(waitResources, 250); // try again in 300 milliseconds setTimeout(addCopyButtonAtelier, 250); // try again in 300 milliseconds
} }
} }
waitResources(); addCopyButtonAtelier();

View file

@ -1,13 +1,22 @@
{ {
"name": "DofusBook Atelier Bouton Copier", "name": "DofusBook Atelier Bouton Copier",
"description": "Ajout d'un bouton pour copier chaque nom de ressource dans l'atelier de DofusBook", "description": "Ajout d'un bouton pour copier chaque nom de ressource dans l'atelier de DofusBook",
"version": "1.0", "version": "1.1.1",
"manifest_version": 3, "manifest_version": 3,
"content_scripts": [ "icons": {
{ "16": "./icons/icon16.png",
"matches": ["https://www.dofusbook.net/fr/outils/atelier"], "32": "./icons/icon32.png",
"js": ["dofusbook.atelier.copy.js"], "48": "./icons/icon48.png",
"run_at": "document_end" "128": "./icons/icon128.png"
} },
"permissions": [
"tabs",
"scripting"
],
"background": {
"service_worker": "background.js"
},
"host_permissions": [
"https://www.dofusbook.net/*"
] ]
} }