forked from jerone/UserScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path37853.user.js
More file actions
208 lines (187 loc) · 7.41 KB
/
Copy path37853.user.js
File metadata and controls
208 lines (187 loc) · 7.41 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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
////////////////////////////////////////////////////////////////////////////
// ==UserScript===
// @name Userscripts.org Timed Updater
// @author Jerone UserScript Productions
// @namespace http://userscripts.org/users/31497
// @homepage http://userscripts.org/scripts/show/37853
// @description Update or create script at specific time.
// @description Userscripts.org Timed Updater v2.0.1 Alpha
// @copyright 2008 - 2012 Jerone
// @version v2.0.1 Alpha
// @browser FF17
// @include *userscripts.org/scripts/new?form=true
// @include *userscripts.org/scripts/edit_src/*
// ==/UserScript==
/*//////////////////////////////////////////////////////////////////////////
// ToC:
// - Copyrights
// - History
// - Todo
// - Note
// - Userscript
// - Statistics
////////////////////////////////////////////////////////////////////////////
THIS SCRIPT IS PROVIDED BY THE AUTHOR `AS IS' AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SCRIPT, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
////////////////////////////////////////////////////////////////////////////
// History:
// [+] = added; [-] = removed; [/] = fixed; [*] = updated;
30-11-2008 13:30 [v1 Alpha]:
[+] initial release;
10-01-2009 19:15 [v1.1 Beta]:
[*] updated framework;
13-11-2010 23:45 [v1.2 Beta]:
[/] fixed bug with form submit;
[*] updated @include page;
[*] cleaned up code;
30-01-2011 21:00 [v2.0 Alpha]:
[*] removed US Framework;
[*] clean up code;
[/] fixed bug with shift, alt and ctrl key;
28-10-2012 13:00 [v2.0.1 Alpha]:
[/] fixed working on https://userscripts.org;
////////////////////////////////////////////////////////////////////////////
// Todo:
// - count down every seconds when below 1 minute;
////////////////////////////////////////////////////////////////////////////
// Note:
// -
/*//////////////////////////////////////////////////////////////////////////
//*** USERSCRIPT ***//
(function (win, doc, und) {
var addEvent = function(node,type,fn,useCapture){if(node.addEventListener){node.addEventListener(type,fn,useCapture);}else if(node.attachEvent){node["e"+type+fn]=fn;node[type+fn]=function(){node["e"+type+fn](win.event);};node.attachEvent("on"+type,node[type+fn]);}};
var UTU = {
init: function(){
var obj;
if((obj = doc.getElementById("script_src"))){
var container = doc.createElement("span");
container.style.display = "block";
var label = doc.createElement("label");
label.htmlFor = label.for = "inputHours";
label.innerHTML = (/new/i.test(location.href) ? "Create" : "Save") + " script at <code>(h:m)</code>: ";
container.appendChild(label);
var inputHours = doc.createElement("input");
inputHours.id = "inputHours";
inputHours.value = new Date().getHours() + 1;
inputHours.size = 2;
inputHours.maxlength = 2;
inputHours.title = "Hours";
inputHours.style.textAlign = "center";
container.appendChild(inputHours);
container.appendChild(doc.createTextNode(" : "));
var inputMinutes = doc.createElement("input");
inputMinutes.id = "inputMinutes";
inputMinutes.value = "00";
inputMinutes.size = 2;
inputMinutes.maxlength = 2;
inputMinutes.title = "Minutes";
inputMinutes.style.textAlign = "center";
container.appendChild(inputMinutes);
var btn = doc.createElement("input");
btn.type = "button";
btn.value = "Activate timer";
btn.title = "Click here to activate the timer to submit this script at a specific time!";
btn.style.marginRight = "10px";
container.appendChild(btn);
var label2 = doc.createElement("label");
label2.htmlFor = label2.for = "inputHours";
label2.innerHTML = "No timer set yet...";
container.appendChild(label2);
var node = obj.nextSibling;
while(node.nodeType==3 || !/\S/.test(node.nodeValue)){
node = node.nextSibling;
}
if(/new/i.test(location.href)){
node.parentNode.insertBefore(container, node.nextSibling);
} else {
node.insertBefore(container, node.firstChild);
}
var interval, timeout;
addEvent(inputHours, "keyup", function(e){
if(e.keyCode==9 || e.keyCode==16 || e.keyCode==17 || e.keyCode==18) return; // tab, shift, ctrl, alt;
if(this.value.length>=2){
inputMinutes.select();
}
btn.disabled = false;
btn.value = "Activate timer";
win.clearInterval(interval);
win.clearTimeout(timeout);
clock();
});
addEvent(inputMinutes, "keyup", function(e){
if(e.keyCode==9 || e.keyCode==16 || e.keyCode==17 || e.keyCode==18) return; // tab, shift, ctrl, alt;
if(this.value.length>=2){
btn.focus();
}
btn.disabled = false;
btn.value = "Activate timer";
win.clearInterval(interval);
win.clearTimeout(timeout);
clock();
});
addEvent(btn, "click", function(){
if(!this.disabled){
this.disabled = true;
this.value = "Timer active";
this.focus();
timeout = win.setTimeout(function(){
var form = doc.evaluate("//form[contains(@action, 'create') or contains(@action, 'edit_src')]", doc, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
form && form.submit && form.submit();
win.clearInterval(interval);
win.clearTimeout(timeout);
}, clock());
interval = win.setInterval(function(){
clock();
}, 30 * 1000); // every half a minute;
}
});
function clock(){
var h = Number(inputHours.value) || 0,
m = Number(inputMinutes.value) || 0,
timer = (new Date().setHours(h, m, 0, 0) - new Date().getTime());
if(timer<0){ // -
timer += 24 * 60 * 60 * 1000; // +24 hour;
}
label2.innerHTML = " ± " + humanize(timer) + " remaining. ";
return timer;
}
function humanize(n, shorten){
shorten = shorten || false;
var txt = false,
unites = [
{name: "millisecond", plural: "milliseconds", min: 0, max: 1000},
{name: "second", plural: "seconds", min: 1000, max: 60*1000},
{name: "minute", plural: "minutes", min: 60*1000, max: 60*60*1000},
{name: "hour", plural: "hours", min: 60*60*1000, max: 24*60*60*1000},
{name: "day", plural: "days", min: 24*60*60*1000, max: 7*24*60*60*1000},
{name: "week", plural: "weeks", min: 7*24*60*60*1000, max: 365*24*60*60*1000},
{name: "year", plural: "years", min: 365*24*60*60*1000, max: Infinity}],
i = 0, unit;
for(; unit = unites[i]; i++){
if(unit.min<=n && n<unit.max){
var val = Math.floor(n / (unit.min || 1)),
one = val==1;
txt = (!one && !shorten ? val + " " : "") + (!one ? unit.plural : unit.name);
}
}
return txt;
}
}
}
};
UTU.init();
})(this, document);
//*** STATISTICS ***//
// Chars (exclude spaces): 6.048
// Chars (include spaces): 7.376
// Chars (Chinese): 0
// Words: 768
// Lines: 208