Minor improvement
diff --git a/console_inject.js b/console_inject.js
index 2b62b9e..f8e5b44 100644
--- a/console_inject.js
+++ b/console_inject.js
@@ -14,6 +14,24 @@
};
}
+function duplicateThreads() {
+ var modal = document.querySelector(".pane[pane-id=\"default-1\"]");
+ var duplicateinto = parseUrl(modal.querySelector("#infinitegforums_duplicateinto").value);
+ if (duplicateinto === false) {
+ return;
+ }
+ modal.querySelector("footer").style.display = "none";
+ var checkboxes = document.querySelectorAll(".thread-group material-checkbox[aria-checked=\"true\"]");
+ modal.querySelector("main").innerHTML = '<p style="text-align: center;">'+chrome.i18n.getMessage("inject_duplicate_progress")+':<br><progress id="infinitegforums_progress" max="'+checkboxes.length+'" value="0"></progress></p>';
+ checkboxes.forEach(checkbox => {
+ var thread = parseUrl(checkbox.parentNode.parentNode.querySelector("a.header-content").href);
+ var script = document.createElement('script');
+ script.textContent = 'fetch("https://support.google.com/s/community/api/MarkDuplicateThread", {"credentials":"include","headers":{"content-type":"text/plain; charset=utf-8"},"body":\'{\"1\":\"'+thread.forum+'\",\"2\":\"'+thread.thread+'\",\"3\":{\"2\":{\"1\":\"'+duplicateinto.forum+'\",\"2\":\"'+duplicateinto.thread+'\"}}}\',"method":"POST","mode":"cors"}).then(_ => { var progress = document.querySelector("#infinitegforums_progress"); progress.value = parseInt(progress.value) + 1; if (progress.value == progress.getAttribute("max")) { location.reload(); } });';
+ document.head.appendChild(script);
+ script.remove();
+ });
+}
+
function mutationCallback(mutationList, observer) {
mutationList.forEach((mutation) => {
if (mutation.type == "childList") {
@@ -55,29 +73,19 @@
modal.classList.add("visible");
modal.style.display = "block";
modal.innerHTML = '<material-dialog role="dialog" aria-modal="true" style="display: block!important; width: 600px; max-width: 100%; margin: 8px auto; padding: 16px 0; background: white; box-shadow: 0 24px 38px 3px rgba(0,0,0,.14), 0 9px 46px 8px rgba(0,0,0,.12), 0 11px 15px -7px rgba(0,0,0,.2);"><header role="presentation" style="padding: 24px 24px 0; width: 100%; box-sizing: border-box;"><div style="color: #202124; font-family: \'Google Sans\',sans-serif; font-size: 18px; font-weight: 400; line-height: 24px; margin-bottom: 4px; text-align: center;">'+chrome.i18n.getMessage("inject_duplicatebtn")+'</div></header><main role="presentation" style="font-size: 13px; font-weight: 400; color: rgba(0,0,0,.87); overflow: auto; padding: 0 24px;"><p><label for="duplicate_thread">'+chrome.i18n.getMessage("inject_duplicateinto")+' </label><input type="url" id="infinitegforums_duplicateinto" placeholder="'+chrome.i18n.getMessage("inject_duplicateinto_placeholder")+'" style="width: 400px;"></p></main><footer role="presentation" style="padding: 0 24px;"><material-button role="button" style="display: inline-block; float: right; color: #1a73e8; height: 36px; min-width: 64px; margin: 0 4px; cursor: pointer;" id="infinitegforums_duplicate"><div class="content" style="line-height: 36px; text-align: center;">'+chrome.i18n.getMessage("inject_duplicate_confirm")+'</div></material-button><material-button role="button" style="display: inline-block; float: right; color: #1a73e8; height: 36px; min-width: 64px; margin: 0 4px; cursor: pointer;" id="infinitegforums_cancel"><div class="content" style="line-height: 36px; text-align: center;">'+chrome.i18n.getMessage("inject_duplicate_cancel")+'</div></material-button><div style="clear: both;"></div></footer></material-dialog>';
+ modal.querySelector("#infinitegforums_duplicateinto").focus();
modal.querySelector("#infinitegforums_cancel").addEventListener("click", function() {
var modal = document.querySelector(".pane[pane-id=\"default-1\"]");
modal.classList.remove("visible");
modal.style.display = "none";
modal.innerHTML = "";
});
- modal.querySelector("#infinitegforums_duplicate").addEventListener("click", function() {
- var modal = document.querySelector(".pane[pane-id=\"default-1\"]");
- var duplicateinto = parseUrl(modal.querySelector("#infinitegforums_duplicateinto").value);
- if (duplicateinto === false) {
- return;
+ modal.querySelector("#infinitegforums_duplicateinto").addEventListener("keypress", function() {
+ if (event.keyCode == 13) {
+ duplicateThreads();
}
- modal.querySelector("footer").style.display = "none";
- var checkboxes = document.querySelectorAll(".thread-group material-checkbox[aria-checked=\"true\"]");
- modal.querySelector("main").innerHTML = '<p style="text-align: center;">'+chrome.i18n.getMessage("inject_duplicate_progress")+':<br><progress id="infinitegforums_progress" max="'+checkboxes.length+'" value="0"></progress></p>';
- checkboxes.forEach(checkbox => {
- var thread = parseUrl(checkbox.parentNode.parentNode.querySelector("a.header-content").href);
- var script = document.createElement('script');
- script.textContent = 'fetch("https://support.google.com/s/community/api/MarkDuplicateThread", {"credentials":"include","headers":{"content-type":"text/plain; charset=utf-8"},"body":\'{\"1\":\"'+thread.forum+'\",\"2\":\"'+thread.thread+'\",\"3\":{\"2\":{\"1\":\"'+duplicateinto.forum+'\",\"2\":\"'+duplicateinto.thread+'\"}}}\',"method":"POST","mode":"cors"}).then(_ => { var progress = document.querySelector("#infinitegforums_progress"); progress.value = parseInt(progress.value) + 1; if (progress.value == progress.getAttribute("max")) { location.reload(); } });';
- document.head.appendChild(script);
- script.remove();
- });
});
+ modal.querySelector("#infinitegforums_duplicate").addEventListener("click", duplicateThreads);
});
}
}