This repository has been archived on 2023-01-26. You can view files and clone it, but cannot push or open issues or pull requests.
scripts-old/src/commandRenamer.js

63 lines
1.9 KiB
JavaScript
Raw Normal View History

2020-07-31 09:25:42 +00:00
import getTranslations from './i18n/commandRenamer';
2020-07-31 09:23:05 +00:00
import wait from './utils/wait';
// ==UserScript==
// @name Command renamer
// @namespace https://github.com/tribalwarshelp/scripts
// @updateURL https://raw.githubusercontent.com/tribalwarshelp/scripts/master/dist/commandRenamer.js
// @downloadURL https://raw.githubusercontent.com/tribalwarshelp/scripts/master/dist/commandRenamer.js
2021-05-08 16:41:04 +00:00
// @version 0.2.4
2020-07-31 09:23:05 +00:00
// @description Command renamer
2021-01-17 08:20:19 +00:00
// @author Kichiyaki https://dwysokinski.me/
2020-07-31 09:23:05 +00:00
// @match *://*/game.php*mode=incomings*
// @grant none
// ==/UserScript==
2020-07-31 09:25:42 +00:00
const translations = getTranslations();
const handleSubmit = async e => {
2020-07-31 09:23:05 +00:00
e.preventDefault();
const name = e.target[0].value;
if (!name) return;
const checkboxes = document.querySelectorAll(
'#incomings_table input:checked'
);
e.target[1].disabled = true;
for (let i = 0; i < checkboxes.length; i++) {
const checkbox = checkboxes[i];
if (checkbox.id === 'select_all') continue;
const icon = checkbox.parentElement.querySelector('.rename-icon');
icon.click();
await wait(20);
const quickeditForm =
checkbox.parentElement.querySelector('.quickedit-edit');
2020-07-31 09:23:05 +00:00
quickeditForm.querySelector('input').value = name;
quickeditForm.querySelector('input[type="button"]').click();
await wait(350);
}
e.target[1].disabled = false;
};
const renderUI = () => {
const html = `
2020-07-31 09:25:42 +00:00
<input type="text" placeholder="${translations.name}" />
<button type="submit">${translations.rename}</button>
2020-07-31 09:23:05 +00:00
`;
const form = document.createElement('form');
form.innerHTML = html;
form.addEventListener('submit', handleSubmit);
document
.querySelector('#paged_view_content')
.insertBefore(form, document.querySelector('#incomings_form'));
};
(async function () {
try {
renderUI();
} catch (error) {
console.log('command renamer', error);
}
})();