forked from jesus2099/konami-command
-
Notifications
You must be signed in to change notification settings - Fork 0
/
INSTALL-USER-SCRIPT.user.js
119 lines (119 loc) · 5.13 KB
/
INSTALL-USER-SCRIPT.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
"use strict";
var meta = {rawmdb: function() {
// ==UserScript==
// @name INSTALL USER SCRIPT
// @version 2016.5.1
// @changelog https://github.com/jesus2099/konami-command/commits/master/INSTALL-USER-SCRIPT.user.js
// @description bitbucket.org, github.com, gitlab.com: Convenient direct “raw” download links (leftmost file icon) to “Install” user scripts from file lists. This will also allow user script auto‐update in most greasemonkey engines, even if the script author has not set @downloadURL and @updateURL.
// @supportURL https://github.com/jesus2099/konami-command/labels/INSTALL-USER-SCRIPT
// @compatible opera(12.18.1872)+violentmonkey my setup
// @compatible firefox(39)+greasemonkey quickly tested
// @compatible chromium(46)+tampermonkey quickly tested
// @compatible chrome+tampermonkey should be same as chromium
// @namespace https://github.com/jesus2099/konami-command
// @downloadURL https://github.com/jesus2099/konami-command/raw/master/INSTALL-USER-SCRIPT.user.js
// @updateURL https://github.com/jesus2099/konami-command/raw/master/INSTALL-USER-SCRIPT.user.js
// @author PATATE12
// @licence CC BY-NC-SA 3.0 (https://creativecommons.org/licenses/by-nc-sa/3.0/)
// @since 2014-11-14
// @icon data:image/gif;base64,R0lGODlhEAAQAMIDAAAAAIAAAP8AAP///////////////////yH5BAEKAAQALAAAAAAQABAAAAMuSLrc/jA+QBUFM2iqA2ZAMAiCNpafFZAs64Fr66aqjGbtC4WkHoU+SUVCLBohCQA7
// @grant none
// @include https://bitbucket.org/*
// @include https://github.com/*
// @include https://gitlab.com/*
// @run-at document-end
// ==/UserScript==
// ==OpenUserJS==
// @unstableMinify it might break metadata block parser
// ==/OpenUserJS==
}};
if (meta.rawmdb && meta.rawmdb.toString && (meta.rawmdb = meta.rawmdb.toString())) {
var kv/*key,val*/, row = /\/\/\s+@(\S+)\s+(.+)/g;
while ((kv = row.exec(meta.rawmdb)) !== null) {
if (meta[kv[1]]) {
if (typeof meta[kv[1]] == "string") meta[kv[1]] = [meta[kv[1]]];
meta[kv[1]].push(kv[2]);
} else meta[kv[1]] = kv[2];
}
}
var supportedFileTypes = [".user.js", ".uc.js", ".uc.xul"];
var host = {
"bitbucket.org": {
css: {
files: "table#source-list tbody td.filename a[title$='%fileType%']",
icon: "span.aui-icon.aui-icon-small.aui-iconfont-devtools-file",
newIcon: "aui-icon aui-icon-small aui-iconfont-devtools-clone", /* https://docs.atlassian.com/aui/5.5.1/docs/icons.html */
},
href: { match: /^(\/[^/]+\/[^/]+)\/src\/[0-9a-f]{40}\/(.+)\?at=(.+)$/, replace: "$1/raw/$3/$2" },
unnestIcon: true,
},
"github.com": {
css: {
files: "table.files tbody td.content a.js-navigation-open[title$='%fileType%']",
icon: "td.icon svg.octicon.octicon-file-text",
/*//TODO: find why a.octicon.octicon-cloud-download does not show icon any more // newIcon: "octicon octicon-cloud-download", /* https://octicons.github.com */
},
href: { match: /(\/[^/]+\/[^/]+)\/blob\//, replace: "$1/raw/" },
iconParentLevel: 3,
dumbMode: true,
},
"gitlab.com": {
css: {
files: "table.tree-table tbody td.tree-item-file-name a[href$='%fileType%']",
icon: "i.fa[class*='fa-file-']",
newIcon: "fa fa-download", /* https://fortawesome.github.io/Font-Awesome/icons/ */
},
href: { match: /(\/[^/]+\/[^/]+)\/blob\//, replace: "$1/raw/" },
iconParentLevel: 2,
dumbMode: true,
},
};
var installImage;
host = host[self.location.host];
host.css.files = supportedFileTypes.map(function(fileType) { return host.css.files.replace(/%fileType%/g, fileType) + ":not(.j2installUserScript)"; }).join(", ");
if (host.dumbMode) {
setInterval(changeStuff, 1000);
} else {
jQuery(document).on("pjax:end", changeStuff); /* https://github.com/defunkt/jquery-pjax#events */
}
changeStuff();
function changeStuff() {
host.files = document.querySelectorAll(host.css.files);
for (var f = 0; f < host.files.length; f++) {
host.files[f].classList.add("j2installUserScript");
var icon = host.files[f];
if (host.iconParentLevel) for (var p = 0; p < host.iconParentLevel; p++) {
icon = icon.parentNode;
}
icon = icon.querySelector(host.css.icon);
if (icon) {
var install = document.createElement("a");
if (host.css.newIcon) {
install.className = host.css.newIcon;
} else {
if (!installImage) {
installImage = document.createElement("img");
installImage.setAttribute("src", meta.icon);
}
install.appendChild(installImage.cloneNode());
install.className = icon.className;
}
install.setAttribute("href", host.files[f].getAttribute("href").replace(host.href.match, host.href.replace));
install.setAttribute("title", "Install “" + host.files[f].getAttribute("title") + "”");
install.style.setProperty("color", "green");
install.addEventListener("click", function(e) {
e.cancelBubble = true;
if (e.stopPropagation) {
e.stopPropagation();
}
return false;
});
if (host.unnestIcon) {
host.files[f].parentNode.insertBefore(install, host.files[f]);
icon.parentNode.removeChild(icon);
} else {
icon.parentNode.replaceChild(install, icon);
}
}
}
}