-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglobal.html
70 lines (65 loc) · 2.28 KB
/
global.html
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
<!DOCTYPE HTML>
<script>
// if event handlers are in the global HTML page register with application:
safari.application.addEventListener("command", performCommand, true);
safari.application.addEventListener("validate", validateCommand, true);
function performCommand(event) {
var webIP = safari.extension.settings.ruIP;
var ruPath = safari.extension.settings.ruDirectory;
var fullPath = webIP.concat(ruPath); //Sometimes ruTorrent is installed at the root directory. Other times it is not.
var uiURL = makeWebUILink(fullPath, event.userInfo.url)
var confirmMSG = getUIConfirm();
if (event.command != "send_to_rutorrent") //Make sure that is the command being executed.
return;
alert(confirmMSG);
event.currentTarget.activeBrowserWindow.openTab().url = uiURL; //For now it has to open a damn window. I'm working on this
}
//You only want a specific critera for the context menu to work.
//Currently this should work on all Gazelle sites I can think of.
//It may work on others too if "torrents.php?action=download" is a valid torrent link
function validateCommand(event) {
if (event.command != "send_to_rutorrent")
return;
if (event.userInfo.name !="A" || event.userInfo.url.search(/torrents\.php\?action=download/) == -1){
event.target.disabled = true;
}
}
//Create the link that will be passed to ruTorrent v3+
function makeWebUILink(webIPforLink, linkhref)
{
var webUI = safari.extension.settings.webUI;
switch(webUI){
case "v3":
return returnSSL()+"://"+webIPforLink+"/php/addtorrent.php?url="+escape(linkhref);
case "v2":
return returnSSL()+"://"+webIPforLink+"/addtorrent.php?url="+escape(linkhref);
case "u":
return returnSSL()+"://"+webIPforLink+"/gui/?action=add-url&s="+escape(linkhref);
default:
return "Something is wrong!";
}
}
//Returns the protocol depending on whether or not you have SSL enabled in the extension settings.
function returnSSL() {
var ruSSL = safari.extension.settings.useSSL;
if (ruSSL == "1") {
return "https";
}
else {
return "http";
}
}
function getUIConfirm(){
var webUI = safari.extension.settings.webUI;
switch(webUI){
case "v3":
return "Sent to ruTorrent v3.";
case "v2":
return "Sent to ruTorrent v2.";
case "u":
return "Sent to uTorrent.";
default:
return "Something is wrong!";
}
}
</script>