forked from jesus2099/konami-command
-
Notifications
You must be signed in to change notification settings - Fork 2
/
lastfm_ALL-LINKS-TO-LOCAL-SITE.user.js
54 lines (54 loc) · 2.54 KB
/
lastfm_ALL-LINKS-TO-LOCAL-SITE.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
(function(){"use strict";
var metadata=function(){/*
// ==UserScript==
// @name last.fm. ALL LINKS TO LOCAL SITE
// @version 2014.6.13.1809
// @description Replaces any lastfm link by the desired language, like "www.lastfm.xx" or else
// @homepage http://userscripts-mirror.org/scripts/show/29156
// @supportURL https://github.com/jesus2099/konami-command/issues
// @namespace https://github.com/jesus2099/konami-command
// @downloadURL https://raw.githubusercontent.com/jesus2099/konami-command/master/lastfm_ALL-LINKS-TO-LOCAL-SITE.user.js
// @updateURL https://raw.githubusercontent.com/jesus2099/konami-command/master/lastfm_ALL-LINKS-TO-LOCAL-SITE.user.js
// @author PATATE12 aka. jesus2099/shamo
// @licence CC BY-NC-SA 3.0 (https://creativecommons.org/licenses/by-nc-sa/3.0/)
// @since 2008-06-26
// @icon data:image/gif;base64,R0lGODlhEAAQAKEDAP+/3/9/vwAAAP///yH/C05FVFNDQVBFMi4wAwEAAAAh/glqZXN1czIwOTkAIfkEAQACAwAsAAAAABAAEAAAAkCcL5nHlgFiWE3AiMFkNnvBed42CCJgmlsnplhyonIEZ8ElQY8U66X+oZF2ogkIYcFpKI6b4uls3pyKqfGJzRYAACH5BAEIAAMALAgABQAFAAMAAAIFhI8ioAUAIfkEAQgAAwAsCAAGAAUAAgAAAgSEDHgFADs=
// @grant none
// @exclude http://cn.last.fm/*
// @exclude http://www.last.fm/*
// @exclude http://www.lastfm.*
// @run-at document-end
// ==/UserScript==
*/};
var preferred_lastfm = "last.fm";
/* In above setting, choose your favourite host :
"last.fm" for minimalistic auto-lang despatch links (often english)
"cn.last.fm" for 简体中文
"www.last.fm" for english
"www.lastfm.com.br" for português
"www.lastfm.com.tr" for türkçe
"www.lastfm.de" → for deutsch
"www.lastfm.es" → for español
"www.lastfm.fr" → for français
"www.lastfm.it" → for italiano
"www.lastfm.jp" → for 日本語
"www.lastfm.pl" → for polski
"www.lastfm.ru" → for руccкий
"www.lastfm.se" → for svenska */
var meta = metadata && metadata.toString && metadata.toString();
meta = meta.match(/@name\s+(.+)/i);
meta = meta?"” ("+meta[1]+")":"”";
var as = document.querySelectorAll("a[href*='.lastfm.'], a[href*='last.fm/']");
for (var i=0; i < as.length; i++) {
var newhref, href = as[i].getAttribute("href");
if (
href &&
(newhref = href.replace(/^(?:https?:)?\/\/(?:(?:cn|www)\.)?(?:last\.fm|lastfm\.(?:com\.)?[a-z][a-z])(\/.*)?$/i, "http://"+preferred_lastfm+"$1")) &&
href != newhref
) {
as[i].setAttribute("href", newhref);
var title = as[i].getAttribute("title");
as[i].setAttribute("title", (title?title+"\n":"")+"was “"+href+meta);
}
}
})();