forked from Xelio/hkg-force-member-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhkg-force-member-server.user.js
81 lines (65 loc) · 2.62 KB
/
hkg-force-member-server.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
// ==UserScript==
// @name HKG Force member server
// @namespace http://xelio.eu.org
// @version 2.0
// @description Force using member server if logged in
// @include http://forum*.hkgolden.com/*
// @include http://search.hkgolden.com/*
// @include http://profile.hkgolden.com/*
// @require http://code.jquery.com/jquery-1.9.1.min.js
// @run-at document-end
// @copyright 2013+, Xelio
// ==/UserScript==
/*
HKG Force member server (HKGolden Force member server)
Copyright (C) 2013 Xelio Cheong
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
var $j = jQuery.noConflict();
// Function for randomizing array
shuffle = function(arr) {
for(
var j, x, i = arr.length; i;
j = Math.random() * i|0,
x = arr[--i], arr[i] = arr[j], arr[j] = x
);
return arr;
}
replaceLink = function() {
$j('a[href^="view.aspx"]').each(function() {
$j(this).attr('href', 'http://' + memberServers[0] + '.hkgolden.com/' + $j(this).attr('href'));
$j(this).attr('target', '_new');
});
}
var memberServers = $j.map(shuffle([9, 10, 11]), function(n, i) {return 'forum' + n;});
var inMemberServer = false;
var loggedIn = false;
var searchResult = false;
var profilePage = false;
var currentServer = window.location.href.match(/(forum\d+|search|profile)/)[0];
memberServers.forEach(function(ele, ind, arr) {
if(currentServer === ele) inMemberServer = true;
});
loggedIn = ($j('a[href="javascript:islogout();"]').length !== 0);
searchResult = window.location.href.match(/search.hkgolden.com\/Search/) !== null;
profilePage = window.location.href.match(/profile.hkgolden.com\/profilepage.aspx/) !== null && $j('#ctl00_ContentPlaceHolder1_mainTab_mainTab0_tab').length !== 0;
if(profilePage || (searchResult && loggedIn)) {
// Replace link target server
replaceLink();
$j('body').bind('DOMNodeInserted', function() {
console.log('DOM node inserted');
replaceLink();
});
} else if(!inMemberServer && loggedIn && !searchResult) {
// redirect to member server
window.location.href = window.location.href.replace(/(forum\d+|search|profile)/, memberServers[0]);
}