[Pkg-mozext-commits] [tabmixplus] 08/56: Fix changeset af1baf9d6f33, Add 'Report a Bug' button in tab-mix-plus page at addons.mozilla.org for all languages

David Prévot taffit at moszumanska.debian.org
Mon Jun 6 00:02:32 UTC 2016


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository tabmixplus.

commit 183b1ecab50fd1b13a77fb4f50c59b7316be01de
Author: onemen <tabmix.onemen at gmail.com>
Date:   Sat May 7 08:58:57 2016 +0300

    Fix changeset af1baf9d6f33, Add 'Report a Bug' button in tab-mix-plus page at addons.mozilla.org for all languages
---
 chrome/content/content.js | 64 ++++++++++++++++++++++++++++-------------------
 1 file changed, 38 insertions(+), 26 deletions(-)

diff --git a/chrome/content/content.js b/chrome/content/content.js
index 558a33c..029a1c3 100644
--- a/chrome/content/content.js
+++ b/chrome/content/content.js
@@ -410,7 +410,7 @@ var ContextMenuHandler = {
   }
 };
 
-const AMO = "https://addons.mozilla.org/en-us/firefox/addon/tab-mix-plus/";
+const AMO = new RegExp("https://addons.mozilla.org/.+/firefox/addon/tab-mix-plus/");
 const BITBUCKET = "https://bitbucket.org/onemen/tabmixplus/issues?status=new&status=open";
 
 var TabmixPageHandler = {
@@ -424,27 +424,48 @@ var TabmixPageHandler = {
       return;
     }
 
-    switch (doc.documentURI.toLowerCase()) {
-      case AMO:
-        if (event.type == "DOMContentLoaded") {
-          this.count = 0;
-          content.addEventListener("pageshow", this);
-        }
-        this.addAMOButton(event.type);
-        break;
-      case BITBUCKET:
-        this.styleBitbucket();
-        break;
+    let uri = doc.documentURI.toLowerCase();
+    if (AMO.exec(uri)) {
+      if (event.type == "DOMContentLoaded") {
+        this.count = 0;
+        content.addEventListener("pageshow", this);
+        this.createAMOButton();
+      }
+      this.moveAMOButton(event.type);
+    } else if (uri == BITBUCKET) {
+      this.styleBitbucket();
+    }
+  },
+
+  buttonID: "tabmixplus-bug-report",
+  createAMOButton: function() {
+    const doc = content.document;
+    const email = doc.querySelector('ul>li>.email[href="mailto:tabmix.onemen at gmail.com"]');
+    if (email && !doc.getElementById(this.buttonID)) {
+      const bugReport = doc.createElement("a");
+      bugReport.href = BITBUCKET;
+      bugReport.textContent = TabmixSvc.getString("bugReport.label");
+      bugReport.id = this.buttonID;
+      bugReport.className = "button";
+      bugReport.target = "_blank";
+      bugReport.style.marginBottom = "4px";
+      let ul = email.parentNode.parentNode;
+      ul.parentNode.insertBefore(bugReport, ul);
     }
   },
 
   count: 0,
-  addAMOButton: function(eventType) {
+  moveAMOButton: function(eventType) {
     const doc = content.document;
     // add-review is null on DOMContentLoaded
     const addReview = doc.getElementById("add-review");
     if (eventType != "pageshow" && !addReview && this.count++ < 10) {
-      this._timeoutID = setTimeout(() => this.addAMOButton("timeout"), 250);
+      this._timeoutID = setTimeout(() => {
+        // make sure content exist after timeout
+        if (content) {
+          this.moveAMOButton("timeout");
+        }
+      }, 250);
       return;
     }
     if (eventType == "pageshow" || addReview) {
@@ -454,18 +475,9 @@ var TabmixPageHandler = {
       clearTimeout(this._timeoutID);
       this._timeoutID = null;
     }
-    const ID = "tabmixplus-bug-report";
-    if (addReview && !doc.getElementById(ID)) {
-      const bugReport = doc.createElement("a");
-      bugReport.href = BITBUCKET;
-      bugReport.textContent = TabmixSvc.getString("bugReport.label");
-      bugReport.id = ID;
-      bugReport.className = "button";
-      bugReport.target = "_blank";
-      bugReport.style.marginBottom = "4px";
-      const div = doc.createElement("DIV");
-      div.appendChild(bugReport);
-      addReview.parentNode.insertBefore(div, addReview);
+    let button = doc.getElementById(this.buttonID);
+    if (addReview && button) {
+      addReview.parentNode.insertBefore(button, addReview);
     }
   },
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/tabmixplus.git



More information about the Pkg-mozext-commits mailing list