Replaces batchduplicate implementation w/ CC flag

The CC now implements batch duplicate functionality, hidden behind the
enableBulkDuplication flag. This commit removes our basic implementation
of that feature and instead force-enables that CC flag when the batch
duplication option is enabled.

Change-Id: Ic2ac504026073087a767c2d264307acb278878da
diff --git a/src/console_inject.js b/src/console_inject.js
index a4ea7db..b2ca80e 100644
--- a/src/console_inject.js
+++ b/src/console_inject.js
@@ -14,33 +14,6 @@
   };
 }
 
-function recursiveParentElement(el, tag) {
-  while (el !== document.documentElement) {
-    el = el.parentNode;
-    if (el.tagName == tag) return el;
-  }
-
-  return undefined;
-}
-
-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(recursiveParentElement(checkbox, "A").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") {
@@ -67,34 +40,6 @@
               node.querySelector(".main-card-content").appendChild(link);
             }
           }
-
-          if (options.batchduplicate && ("tagName" in node) && node.tagName == "MATERIAL-BUTTON" && node.getAttribute("debugid") !== null && (node.getAttribute("debugid") == "mark-read-button" || node.getAttribute("debugid") == "mark-unread-button") && ("parentNode" in node) && document.querySelector("[debugid=\"batchduplicate\"]") === null && node.parentNode !== null && ("parentNode" in node.parentNode) && node.parentNode.parentNode !== null && ("tagName" in node.parentNode.parentNode) && node.parentNode.parentNode.tagName == "EC-BULK-ACTIONS") {
-            var clone = node.cloneNode(true);
-            clone.setAttribute("debugid", "batchduplicate");
-            clone.setAttribute("title", chrome.i18n.getMessage("inject_duplicatebtn"));
-            clone.querySelector("material-icon").setAttribute("icon", "control_point_duplicate");
-            clone.querySelector("i.material-icon-i").innerText = "control_point_duplicate";
-            node.parentNode.prepend(clone);
-            clone.addEventListener("click", function() {
-              var modal = document.querySelector(".pane[pane-id=\"default-1\"]");
-              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_duplicateinto").addEventListener("keypress", function() {
-                if (event.keyCode == 13) {
-                  duplicateThreads();
-                }
-              });
-              modal.querySelector("#infinitegforums_duplicate").addEventListener("click", duplicateThreads);
-            });
-          }
         }
       });
     }
diff --git a/src/console_inject_start.js b/src/console_inject_start.js
index fef90f7..047f2b7 100644
--- a/src/console_inject_start.js
+++ b/src/console_inject_start.js
@@ -1,11 +1,15 @@
 chrome.storage.sync.get(null, function(items) {
-  if (items.loaddrafts || items.escalatethreads || items.movethreads) {
+  if (items.loaddrafts || items.batchduplicate) {
     var startup = JSON.parse(document.querySelector("html").getAttribute("data-startup"));
 
     if (items.loaddrafts) {
       startup[4][13] = true;
     }
 
+    if (items.batchduplicate) {
+      startup[4][58] = true;
+    }
+
     document.querySelector("html").setAttribute("data-startup", JSON.stringify(startup));
   }
 });