Compare commits

..

No commits in common. "main" and "v1.0.0" have entirely different histories.
main ... v1.0.0

3 changed files with 22 additions and 59 deletions

View file

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

View file

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