5
5
// @description gets multiple torrents which you select in rutorrent
6
6
// @include http://*ruTorrent*
7
7
// @include https://*ruTorrent*
8
- // @version 3.0
8
+ // @version 3.1
9
9
// @grant none
10
10
// @downloadURL https://github.com/hannsen/userscripts/raw/master/Rutorrent%20GetMulitpleTorrents.user.js
11
11
// @updateURL https://github.com/hannsen/userscripts/raw/master/Rutorrent%20GetMulitpleTorrents.user.js
12
12
// ==/UserScript==
13
13
14
- var nav_bar = document . getElementById ( "t" ) ;
14
+ const nav_bar = document . getElementById ( "t" ) ;
15
15
16
- var unfoldLink = document . createElement ( 'a' ) ;
17
- var newHTML = document . createElement ( 'div' ) ;
16
+ const unfoldLink = document . createElement ( 'a' ) ;
17
+ const newHTML = document . createElement ( 'div' ) ;
18
18
newHTML . id = 'moved' ;
19
19
unfoldLink . appendChild ( newHTML ) ;
20
20
unfoldLink . id = 'grab' ;
@@ -27,17 +27,36 @@ if (nav_bar) {
27
27
}
28
28
29
29
function getTorrents ( ) {
30
- var selected = document . getElementsByClassName ( "selected" ) ;
31
- var dl_link = 'plugins/source/action.php?hash= ' ;
30
+ const selected = document . getElementsByClassName ( "selected" ) ;
31
+ let dl_link = 'plugins/source/action.php' ;
32
32
33
33
if ( '/' != window . location . toString ( ) . slice ( - 1 ) ) {
34
34
dl_link = '/' + dl_link ;
35
35
}
36
36
37
- for ( var i = 0 ; i < ( selected . length - 1 ) ; i ++ ) {
38
- var hash = selected [ i ] . id ;
37
+ function downloadTorrent ( hash ) {
38
+ const form = document . createElement ( "form" ) ;
39
+ form . setAttribute ( "method" , "post" ) ;
40
+ form . setAttribute ( "action" , dl_link ) ;
41
+ form . setAttribute ( "target" , "_blank" ) ;
42
+
43
+ const input = document . createElement ( "input" ) ;
44
+ input . type = "hidden" ;
45
+ input . name = "hash" ;
46
+ input . value = hash ;
47
+ form . appendChild ( input ) ;
48
+
49
+ document . body . appendChild ( form ) ;
50
+
51
+ form . submit ( ) ;
52
+
53
+ document . body . removeChild ( form ) ;
54
+ }
55
+
56
+ for ( let i = 0 ; i < ( selected . length - 1 ) ; i ++ ) {
57
+ let hash = selected [ i ] . id ;
39
58
if ( hash && hash . match ( / [ A - F 0 - 9 ] { 40 } / i) ) {
40
- window . open ( window . location + dl_link + hash ) ;
59
+ downloadTorrent ( hash ) ;
41
60
}
42
61
}
43
62
}
0 commit comments