-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
executable file
·185 lines (156 loc) · 4.31 KB
/
Copy pathscript.js
File metadata and controls
executable file
·185 lines (156 loc) · 4.31 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
const chars = "abcdefghijklmnopqrstuvwxyz0123456789".split("");
const randomLength = 6;
const urlBase = "https://prnt.sc/";
function getCurrentUrl() {
const buttons = $("#button-pack");
const inputUrl = $("input[name=start-url]").val();
if (!inputUrl) {
buttons.hide();
log("Please enter an URL", "danger");
return;
}
const match = inputUrl.match(/^(https:\/\/prnt.sc\/)([0-9a-z]+)/);
if (!match) {
buttons.hide();
log("What is this URL?", "danger");
return;
}
const url = match[0];
const baseUrl = match[1];
const imageId = match[2];
buttons.show();
return [url, baseUrl, imageId];
}
function setCurrentUrl(url) {
$("input[name=start-url]").val(url);
}
function loadUrl() {
const inputUrl = getCurrentUrl();
if (!inputUrl) return;
const url = inputUrl[0];
const imageId = inputUrl[2];
log("Loading: " + url);
console.log('url', url);
// $.get(url, function (content) {
// const r = content.match(/https:\/\/image\.prntscr\.com\/image\/.*?\.(png|jpeg|jpg)/);
//
// const container = $("#content-container");
//
// if (!r) {
// log("Failed to load image " + imageId, "danger");
// return;
// }
// const imageUrl = r[0];
//
// let img = $("<img/>");
//
// img.one("load", function () {
// log(false);
// container.empty();
// container.append(img);
// });
//
// img.attr("src", imageUrl);
//
// }, "html");
const container = $("#content-container");
container.empty();
container.append('<iframe src="' + url + '" frameborder="0" style="width: 100%;height: 100vh"></iframe>');
}
function nextId(url) {
const charsLen = chars.length;
const str = url.split("");
const reversed = str.reverse();
for (const k in reversed) {
const char = reversed[k];
const index = chars.indexOf(char);
if (index == -1) {
log("What is this sorcery??", "danger");
return false;
}
if (index + 1 == charsLen) {
reversed[k] = chars[0];
continue;
}
reversed[k] = chars[index + 1];
break;
}
return reversed.reverse().join("");
}
function prevId(url) {
const charsLen = chars.length;
const str = url.split("");
const reversed = str.reverse();
for (const k in reversed) {
const char = reversed[k];
const index = chars.indexOf(char);
if (index == -1) {
log("What is this sorcery??", "danger");
return false;
}
if (index == 0) {
reversed[k] = chars[charsLen - 1];
continue;
}
reversed[k] = chars[index - 1];
break;
}
return reversed.reverse().join("");
}
function loadPrev() {
const inputUrl = getCurrentUrl();
if (!inputUrl) return;
const url = inputUrl[1] + prevId(inputUrl[2]);
setCurrentUrl(url);
loadUrl();
}
function loadNext() {
const inputUrl = getCurrentUrl();
if (!inputUrl) return;
const url = inputUrl[1] + nextId(inputUrl[2]);
setCurrentUrl(url);
loadUrl();
}
// "They did research, you know.. 60% of the time - it work's every time! ;-)"
function randomPage() {
let random = [];
for (let i = 0; i < randomLength; i++) {
random[i] = chars[Math.floor(Math.random() * chars.length)];
}
const url = urlBase + random.join("");
setCurrentUrl(url);
loadUrl();
}
let lastLogClass = null;
function log(str, type) {
const log = $("#log");
type = (typeof type !== 'undefined') ? type : "info";
if (!str) {
log.hide();
return;
}
const alertClass = "alert-" + type;
if (!lastLogClass) {
lastLogClass = alertClass;
log.addClass(alertClass);
}
if (lastLogClass && lastLogClass != alertClass) {
log.removeClass(lastLogClass);
lastLogClass = alertClass;
log.addClass(alertClass);
}
log.show();
log.text(str);
}
$(document).ready(function () {
log(false);
});
document.onkeydown = function (e) {
e = e || window.event;
const key = e.key;
if (key.toLowerCase() == 'p') {
loadPrev();
} else if (key.toLowerCase() == 'n') {
loadNext();
}
};