AMO: Manage My Submisions - View Listing Links

Add/change add-ons view/edit link on AMO DevHub

/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

// ==UserScript==
// @id              amo-manage-my-submission@loucypher
// @name            AMO: Manage My Submisions - View Listing Links
// @namespace       https://userscripts.org/users/12
// @description     Add/change add-ons view/edit link on AMO DevHub
// @version         2.1
// @author          LouCypher
// @license         MPL 2.0
// @icon            https://addons.cdn.mozilla.net/media//img/addon-icons/default-32.png
// @icon64URL       https://addons.cdn.mozilla.net/media//img/addon-icons/default-64.png
// @screenshot      https://lh5.googleusercontent.com/-hAU-7oNHm38/Um6TLAwS39I/AAAAAAAAD3k/hWvGCMidfZQ/s200/amo-manage-my-submission.png
// @contributionURL http://loucypher.github.io/userscripts/donate.html?AMO%3A+Manage+My+Submisions
// @homepageURL     https://userscripts.org/scripts/show/179837
// @supportURL      https://userscripts.org/scripts/discuss/179837
// @resource        LICENSE https://raw.github.com/LouCypher/userscripts/master/licenses/MPL/LICENSE.txt
// @include         /^https://addons\.mozilla\.org/.*/developers/(addons|themes)(?=\?.*)?/
// @grant           GM_addStyle
// ==/UserScript==

GM_addStyle('.icon-edit, .icon-acr {\
  display: inline-block;\
  margin-left: .5em;\
  width: 12px;\
  height: 12px;\
}\
  .icon-edit {\
  background: url("data:image/png;base64,\
iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A\
/wD/oL2nkwAAAc1JREFUKM91Ut1LU3EYfn6/386mTYfz40KKJIK2bBWSKNT6AocXtcpcH2ygFxJ1\
2U230kU34YX/gSDSB46hbEh2oVSGWV5UKAZjRbg13ZxnenY8up1zfLsqpOYL793zvDwfLyMi7DeD\
jx7fPpmc6T+c/HKiKKzv1cTqPRBR2cWNb4HrTz/SUuI7lSZGjNL98/T1OGZ4ucusK+6rcdufOZo9\
+LRRay63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+8Mgu9eIPa2dfL9kTae\
fz/Hj6/fXPy/lB/unRowqk8+ha7y7O0rREe72DRNvPJLmnqR5YHKLv282D8F4B/Y/ZofmTW2EAkd\
wdLyZ0i5DCLCBhHOho9hYWEe+/v7IwDSND09/SwcDseKxaLTbDY9UkoEg0Hs7OzAdV0QEbxerxMI\
BDylUum5VqvVYkIIR9M0jxCCmZkURWG/3w8pJRERSyk91WrVsSwr9heceQ7HMuS8nAAAAABJRU5E\
rkJggg==") 0 0 no-repeat\
}');

var items = $$("#sorter + .items > .item.addon > .info");
if (items.length) {
  var editLink, viewLink, tooltip;
  for (var i = 0; i < items.length; i++) {
    editLink = $("h3 a", items[i]);
    if (editLink) {
      tooltip = $("a.tooltip", items[i]);
      editLink.parentNode.appendChild(addLink(editLink.getAttribute("href"),
                                              tooltip.title,
                                              "icon-edit"));
      viewLink = $(".more-actions-popup > ul:last-child > li a", items[i]);
      if (viewLink) {
        editLink.href = viewLink.getAttribute("href");
        editLink.title = viewLink.textContent;
        editLink.classList.add("tooltip");

        var addonId = items[i].parentNode.dataset.addonid;
        var acrLink = editLink.parentNode.appendChild(addLink("../compatibility/reporter?guid=" +
                                                              addonId,
                                                              "Compatibility reports",
                                                              "icon-acr"));
      }
      else
        editLink.href = "/" + document.documentElement.lang + "/" + document.body.dataset.app
                      + editLink.href.match(/\/(addon|theme)\/.*\//)[0].toString()
                                     .replace(/\/theme\//, "/addon/");
    }
  }
}

function $(aSelector, aNode) {
  return (aNode || document).querySelector(aSelector);
}

function $$(aSelector, aNode) {
  return (aNode || document).querySelectorAll(aSelector);
}

function addLink(aHref, aTitle, aClassName) {
  var link = document.createElement("a");
  link.href = aHref;
  link.className = aClassName + " tooltip";
  link.title = aTitle;
  return link;
}