Skip to content

Commit

Permalink
Visually mark changed anchors.
Browse files Browse the repository at this point in the history
Criss‐Cross‐Combine features of mb-Preferred-MBS × USO-to-USMO.
  • Loading branch information
jesus2099 committed Jan 14, 2016
1 parent b4782a9 commit ae58012
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 29 deletions.
52 changes: 35 additions & 17 deletions USO-to-USMO.user.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// ==UserScript==
// @name USO to USMO
// @version 2015.7.31.2222
// @version 2016.1.14
// @changelog https://github.com/jesus2099/konami-command/commits/master/USO-to-USMO.user.js
// @description and userscripts.org links lead to userscripts-mirror.org — all kinds: http/https, www/no-www, short/long
// @description and userscripts.org links lead to userscripts-mirror.org — all kinds: http/https, www/no-www, short/long — bypass this script by holding CTRL+ALT+SHIFT
// @coming-soon https://github.com/jesus2099/konami-command/labels/USO-to-USMO
// @inspiration http://userscripts-mirror.org/scripts/show/487275
// @supportURL https://github.com/jesus2099/konami-command/issues
// @compatible opera(12.17)+violentmonkey my own setup
Expand All @@ -16,26 +17,43 @@
// @licence CC BY-NC-SA 3.0 (https://creativecommons.org/licenses/by-nc-sa/3.0/)
// @since 2015-07-30
// @icon data:image/gif;base64,R0lGODlhEAAQAMIDAAAAAIAAAP8AAP///////////////////yH5BAEKAAQALAAAAAAQABAAAAMuSLrc/jA+QBUFM2iqA2ZAMAiCNpafFZAs64Fr66aqjGbtC4WkHoU+SUVCLBohCQA7
// @require https://greasyfork.org/scripts/10888-super/code/SUPER.js?version=84017&v=2015.11.2
// @grant none
// @exclude http://userscripts-mirror.org/*
// @run-at document-start
// ==/UserScript==
"use strict";
document.addEventListener("mousedown", uso2usmo);
function uso2usmo(event) {
var element = event.target || event.srcElement;
if (element && element.tagName == "A") {
var href = element.getAttribute("href");
var hrefMatch = href && href.match(/^(https?:)?(\/\/)?(www\.)?(userscripts\.org)(:\d+)?(\/.*)?(\?.*)?(#.*)?$/);
if (hrefMatch) {
/* an USO link was (left/middle/right) mouse clicked */
/* expand short path (uso/123456 → uso/scripts/show/123456) */
var shortPath = hrefMatch[6];
if (shortPath && (shortPath = shortPath.match(/^\/(\d+)\/?$/))) {
href = href.replace(shortPath[0], "/scripts/show/" + shortPath[1]);
if (document.body) {
document.body.addEventListener("mousedown", function(event) {
if (!event.altKey || !event.ctrlKey || !event.shiftKey) {
var element = event.target || event.srcElement;
if (element && element.nodeType == Node.ELEMENT_NODE) {
if (element.tagName != "A") {
element = getParent(element, "a");
}
if (element && element.tagName == "A" && !element.classList.contains("jesus2099-bypass-USO-to-USMO")) {//not linked yet
var HREF = element.getAttribute("href");
var hrefMatch = HREF && HREF.match(/^(https?:)?(\/\/)?(www\.)?(userscripts\.org)(:\d+)?(\/.*)?(\?.*)?(#.*)?$/);
var newHref = HREF;
if (hrefMatch) {
/* an USO link was (left/middle/right) mouse clicked */
/* expand short path (uso/123456 → uso/scripts/show/123456) */
var shortPath = hrefMatch[6];
if (shortPath && (shortPath = shortPath.match(/^\/(\d+)\/?$/))) {
newHref = newHref.replace(shortPath[0], "/scripts/show/" + shortPath[1]);
}
/* USO to USMO */
newHref = newHref.replace((hrefMatch[1] ? hrefMatch[1] : "") + (hrefMatch[2] ? hrefMatch[2] : "") + (hrefMatch[3] ? hrefMatch[3] : "") + hrefMatch[4], "http://userscripts-mirror.org");
element.setAttribute("href", newHref);
element.style.setProperty("border", "1px dashed gold");
var tooltip = element.getAttribute("title") || "";
if (tooltip) {
tooltip += "\r\n"
}
element.setAttribute("title", tooltip + "old: " + HREF + "\r\nnew: " + newHref);
}
}
}
/* USO to USMO */
element.setAttribute("href", href.replace((hrefMatch[1] ? hrefMatch[1] : "") + (hrefMatch[2] ? hrefMatch[2] : "") + (hrefMatch[3] ? hrefMatch[3] : "") + hrefMatch[4], "http://userscripts-mirror.org"));
}
}
});
}
32 changes: 20 additions & 12 deletions mb_PREFERRED-MBS.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@
// @changelog https://github.com/jesus2099/konami-command/commits/master/mb_PREFERRED-MBS.user.js
// @description choose your favourite MusicBrainz server (http/https, main/beta) and no link will ever send you to the others — bypass this script by holding CTRL+ALT+SHIFT
// @coming-soon https://github.com/jesus2099/konami-command/labels/mb_PREFERRED-MBS
// @inspiration http://userscripts-mirror.org/scripts/show/487275
// @supportURL https://github.com/jesus2099/konami-command/issues
// @compatible opera(12.17)+violentmonkey my own setup
// @compatible firefox(39)+greasemonkey quickly tested
// @compatible chromium(46)+tampermonkey quickly tested
// @compatible chrome+tampermonkey should be same as chromium
// @namespace jesus2099/shamo
// @downloadURL https://github.com/jesus2099/konami-command/raw/master/mb_PREFERRED-MBS.user.js
// @updateURL https://github.com/jesus2099/konami-command/raw/master/mb_PREFERRED-MBS.user.js
Expand All @@ -32,19 +36,23 @@ if (document.body) {
element = getParent(element, "a");
}
if (element && element.tagName == "A" && !element.classList.contains("jesus2099-bypass-mb_PREFERRED-MBS")) {//linked in mb_COOL-ENTITY-LINKS, mb_SUPER-MIND-CONTROL-II-X-TURBO
var href = element.getAttribute("href");
if (href) {
var hrefMatch = href.match(/^(https?:)?(\/\/)?(beta\.)?(musicbrainz\.org)(:\d+)?(\/.*)?(\?.*)?(#.*)?$/);
var HREF = element.getAttribute("href");
if (HREF) {
var hrefMatch = HREF.match(/^(https?:)?(\/\/)?(beta\.)?(musicbrainz\.org)(:\d+)?(\/.*)?(\?.*)?(#.*)?$/);
var newHref = preferredMBS;
if (hrefMatch) {
element.setAttribute("href",
preferredMBS
+ (hrefMatch[5] ? hrefMatch[5] : "")
+ (hrefMatch[6] ? hrefMatch[6] : "")
+ (hrefMatch[7] ? hrefMatch[7] : "")
+ (hrefMatch[8] ? hrefMatch[8] : "")
);
} else if (location.href.match(/^https?:\/\/(beta\.)?musicbrainz\.org/) && href.match(/^\/[^/]/)) {
element.setAttribute("href", preferredMBS + href);
newHref += (hrefMatch[5] ? hrefMatch[5] : "") + (hrefMatch[6] ? hrefMatch[6] : "") + (hrefMatch[7] ? hrefMatch[7] : "") + (hrefMatch[8] ? hrefMatch[8] : "");
} else if (location.href.match(/^https?:\/\/(beta\.)?musicbrainz\.org/) && HREF.match(/^\/[^/]/)) {
newHref += HREF;
}
if (newHref != preferredMBS) {
element.setAttribute("href", newHref);
element.style.setProperty("border", "1px dashed gold");
var tooltip = element.getAttribute("title") || "";
if (tooltip) {
tooltip += "\r\n"
}
element.setAttribute("title", tooltip + "old: " + HREF + "\r\nnew: " + newHref);
}
}
}
Expand Down

0 comments on commit ae58012

Please sign in to comment.