-
Notifications
You must be signed in to change notification settings - Fork 1
/
MirrorPage.user.js
41 lines (37 loc) · 1.41 KB
/
MirrorPage.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
// ==UserScript==
// @name Mirror Page
// @namespace mailto:[email protected]
// @description POSTs page to dynamic page mirror
// @include https://novel18.syosetu.com/*
// @include http://novel18.syosetu.com/*
// @version 1
// @grant GM.xmlHttpRequest
// ==/UserScript==
var ihtml = document.getElementsByTagName("html")[0].innerHTML;
String.prototype.hashCode = function() {
var hash = 0;
if (this.length == 0) {
return hash;
}
for (var i = 0; i < this.length; i++) {
char = this.charCodeAt(i);
hash = ((hash<<5)-hash)+char;
hash = Math.abs(hash & hash); // Convert to 32bit positive integer
}
return hash;
}
var hash = ihtml.hashCode();
GM.xmlHttpRequest({
method: 'POST',
url: 'http://dynamicmirror.herokuapp.com/index.php',
//url: 'http://localhost:21802/index.php',
data: "pageContents=" + encodeURIComponent(ihtml) + "&url=" + encodeURIComponent(document.URL) + "&hash=" + encodeURIComponent(hash),
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
onerror: function (response) { alert("Error in POST"); },
onload: function (response) {
//window.alert(response.responseText); //generic debug code.
//window.location.href = 'http://localhost:21802/latestpage.html';
window.location.href = 'http://dynamicmirror.herokuapp.com/' + hash + '.html';
},
synchronous: true
});