-
Notifications
You must be signed in to change notification settings - Fork 12
/
AMO_Editors.user.js
64 lines (55 loc) · 2.78 KB
/
AMO_Editors.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// ==UserScript==
// @name AMO Editors
// @namespace https://github.com/Ede123/userscripts
// @version 0.94
// @description Automates and improves some things for AMO editors
// @icon https://raw.githubusercontent.com/Ede123/userscripts/master/icons/AMO.png
// @author Eduard Braun <[email protected]>
// @license GPL-3.0-or-later; https://www.gnu.org/licenses/gpl-3.0.txt
// @include https://addons.mozilla.org/*/addon/*
// @include https://addons.mozilla.org/*/editors/review/*
// @include https://addons.mozilla.org/*/files/browse/*
// @include https://addons.mozilla.org/*/files/compare/*
// @grant GM_addStyle
// @require https://raw.githubusercontent.com/darcyclarke/Detect.js/master/detect.min.js
// @run-at document-start
// ==/UserScript==
var href = window.location.href;
/** add styles at "document-start" **/
// avoid line breaks in file viewer whenever possible by using full width of window
if (href.indexOf("/files/") != -1) {
GM_addStyle(".file-viewer .section { width: unset; max-width: 95%;}" +
".file-viewer .syntaxhighlighter .line {max-width: unset;}");
}
/** modify DOM on DOMContentLoaded **/
addEventListener('DOMContentLoaded', function() {
// add a "Review" button to add-on listings
if (href.indexOf("/addon/") != -1) {
var widgets = document.getElementsByClassName("widgets")[0];
var p = document.createElement("p");
var button = document.createElement("a");
button.classList.add("button", "developer", "prominent");
button.href = href.replace(/\/addon\//, "/editors/review/");
var button_span = document.createElement("span");
button_span.textContent = "Review";
button.appendChild(button_span);
p.appendChild(button);
widgets.parentNode.insertBefore(p, widgets.nextSibling);
}
// pre-fill "Tested on:" fields with current user agent data
else if (href.indexOf("/editors/review/") != -1) {
var inputOS = document.getElementById("id_operating_systems");
var inputApp = document.getElementById("id_applications");
var ua = detect.parse(navigator.userAgent);
inputOS.value = ua.os.name;
inputApp.value = ua.browser.family + " " + ua.browser.major + "." + ua.browser.minor;
// add a button to clear the fields again (e.g. on trivial updates which where not tested)
var button = document.createElement("a");
button.href = "javascript:void(0);";
button.textContent = "⌫";
button.classList.add("button");
button.style = "float: right; padding: 2px 5px; border-radius: 5px;";
button.addEventListener("click", function() {inputOS.value = ""; inputApp.value = "";});
inputApp.parentNode.appendChild(button);
}
}, false);