-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfetch.js
More file actions
130 lines (90 loc) · 3.4 KB
/
fetch.js
File metadata and controls
130 lines (90 loc) · 3.4 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
var WScommands = new Object;
function addCommands(commands) {
for (var cmd in commands) {
WScommands[cmd.toLowerCase()] =
new Array(commands[cmd][0], commands[cmd][1], commands[cmd][2]);
}
}
// Command URLs can contain the following replacement tokens:
// %s - This token is replaced by any search terms
// provided when the command is run.
// %r - Replaced by the url of the page you were
// on when the command was run.
// this gets a random item
function random_item(items) {
return items[Math.floor(Math.random()*items.length)];
}
// 28-APr-2021 - taken over "yp" and "mj"
var items = ["d", "mg", "q", "pre", "bv"];
// var DefaultCommand = 'd';
var DefaultCommand = random_item(items);
// add the hotwords
addCommands(hotwords);
// returns parameter values from the url of this page.
function gup() {
var name = ("fetch").replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var results = new RegExp("[\\?&]"+name+"=([^&#]*)").exec(window.location.href);
if (results === null) return "";
else return results[1];
}
// process the command
function processCommand(command) {
var words = command.replace(/%20/g, " ").replace(/\+/g, " ").split(' ');
var cmd = words.shift().toLowerCase();
var args = words.join('%20');
var ref = document.referrer;
//If the command is not recognized, use the default command.
if (typeof WScommands[cmd] == 'undefined') {
if (DefaultCommand !== "") {
args = cmd + ' ' + args;
cmd = DefaultCommand;
}
else {
alert("Undefined command!");
}
}
var url = WScommands[cmd][1];
if (url.indexOf('%r') == -1) { ref = ""; }
if (args === "" && ref === "" && url.indexOf('%s') != -1) {
//If there are no arguments present, let's just go to the root of the domain.
var re = new RegExp('https?:\/\/[^\/]*\/');
var m = re.exec(url);
url = m[0];
}
// commented out the "fetch way"
// top.location.replace(url.replace(/%s/g, args).replace(/%r/g, ref));
// multiparam processing
var s = args;
query='';
urlchunks=url.split('%s');
schunks=s.split('%3B');
for (i=0; i<schunks.length; i++) {
query+=urlchunks[i]+schunks[i];
}
top.location.replace(query);
}
//If the url's "fetch" param has a value then there is no need to load the page,
//we can just start processing the command instead.
var fetch_param=gup();
if (fetch_param !== "") { processCommand(fetch_param); }
//This function runs when the page finishes loading.
function goOnLoad() {
document.getElementById("search-text").focus();
var cmdTable = document.createElement("table");
for (var cmd in WScommands) {
cmdTable.innerHTML += '<tr title="' + WScommands[cmd][0] + '"><td class="trigger">' + WScommands[cmd][0] + '</td><td class="description">' + cmd + '</td><td class="description">' + WScommands[cmd][2] + '</td></tr>';
}
document.getElementById('ocontent').appendChild(cmdTable);
}
function initScreen() { setTimeout("window.scrollTo(0,1);", 100); }
// Function to Get the Commands that match the filtering
function filterIt (SiteType) {
for (var k in WScommands) {
if (WScommands[k][2] == SiteType) {
console.log(WScommands[k][0] + " > " + k);
}
}
}
// index = Cats.findIndex(cat => cat === "sites");
// this works and is what I will use
// filterIt(Cats[Cats.findIndex(cat => cat === x)]);