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-01-01 17:03:36 +00:00
|
|
|
// @version 0.2.1
|
2020-07-31 09:23:05 +00:00
|
|
|
// @description Command renamer
|
2021-01-01 17:03:36 +00:00
|
|
|
// @author Kichiyaki https://dawid-wysokinski.pl/
|
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();
|
|
|
|
|
2020-07-31 09:23:05 +00:00
|
|
|
const handleSubmit = async (e) => {
|
|
|
|
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'
|
|
|
|
);
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
})();
|