-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathredirect.user.js
56 lines (42 loc) · 1.38 KB
/
redirect.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
// ==UserScript==
// @name EliRedirect
// @namespace https://politicsandwar.com/nation/id=97917
// @version 0.1
// @description allows a parsable url for requests to redirect to the bank page
// @author Eligos
// @match https://politicsandwar.com/nation/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=politicsandwar.com
// @grant none
// ==/UserScript==
(async function () {
"use strict";
if (!window.location.href.includes("request")) {
return;
}
var vars = {};
var parts = window.location.href.replace(
/[?&]+([^=&]+)=([^&]*)/gi,
function (m, key, value) {
vars[key] = value;
}
);
const id = window.location.href.match(/id=(\d+)/)[1];
const linkElement = document.querySelector('a[href*="/alliance/"]');
const href = linkElement.getAttribute("href");
const alliance = href.match(/id=(\d+)/)[1];
var url = `https://politicsandwar.com/alliance/id=${alliance}&display=bank`;
if (vars.recipient) {
url += "&recipient=" + vars.recipient;
} else if (id) {
url += `&recipient=${id}&type=ID`;
} else {
return;
}
['food', 'uranium', 'iron', 'bauxite', 'coal', 'oil', 'steel', 'munitions', 'aluminum', 'gasoline', 'money', 'type', 'note']
.forEach(param => {
if (vars[param]) {
url += "&" + param + "=" + vars[param];
}
});
window.location.href = url;
})();