Add $.queueTask.
This commit is contained in:
parent
bb31bc3b93
commit
82a541b2d2
@ -480,6 +480,30 @@
|
|||||||
open: function(url) {
|
open: function(url) {
|
||||||
return (GM_openInTab || window.open)(url, '_blank');
|
return (GM_openInTab || window.open)(url, '_blank');
|
||||||
},
|
},
|
||||||
|
queueTask: (function() {
|
||||||
|
var execTask, taskChannel, taskQueue;
|
||||||
|
taskQueue = [];
|
||||||
|
execTask = function() {
|
||||||
|
var args, func, task;
|
||||||
|
task = taskQueue.shift();
|
||||||
|
func = task[0];
|
||||||
|
args = Array.prototype.slice.call(task, 1);
|
||||||
|
return func.apply(func, args);
|
||||||
|
};
|
||||||
|
if (window.MessageChannel) {
|
||||||
|
taskChannel = new MessageChannel();
|
||||||
|
taskChannel.port1.onmessage = execTask;
|
||||||
|
return function() {
|
||||||
|
taskQueue.push(arguments);
|
||||||
|
return taskChannel.port2.postMessage(null);
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return function() {
|
||||||
|
taskQueue.push(arguments);
|
||||||
|
return setTimeout(execTask, 0);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
})(),
|
||||||
globalEval: function(code) {
|
globalEval: function(code) {
|
||||||
var script;
|
var script;
|
||||||
script = $.el('script', {
|
script = $.el('script', {
|
||||||
@ -489,9 +513,10 @@
|
|||||||
return $.rm(script);
|
return $.rm(script);
|
||||||
},
|
},
|
||||||
unsafeWindow: window.opera && window || unsafeWindow || (function() {
|
unsafeWindow: window.opera && window || unsafeWindow || (function() {
|
||||||
d.createElement('p');
|
var p;
|
||||||
|
p = d.createElement('p');
|
||||||
p.setAttribute('onclick', 'return window');
|
p.setAttribute('onclick', 'return window');
|
||||||
return el.onclick();
|
return p.onclick();
|
||||||
})(),
|
})(),
|
||||||
shortenFilename: function(filename, isOP) {
|
shortenFilename: function(filename, isOP) {
|
||||||
var threshold;
|
var threshold;
|
||||||
|
|||||||
@ -366,6 +366,26 @@ $.extend $,
|
|||||||
return
|
return
|
||||||
open: (url) ->
|
open: (url) ->
|
||||||
(GM_openInTab or window.open) url, '_blank'
|
(GM_openInTab or window.open) url, '_blank'
|
||||||
|
queueTask:
|
||||||
|
# inspired by https://www.w3.org/Bugs/Public/show_bug.cgi?id=15007
|
||||||
|
(->
|
||||||
|
taskQueue = []
|
||||||
|
execTask = ->
|
||||||
|
task = taskQueue.shift()
|
||||||
|
func = task[0]
|
||||||
|
args = Array::slice.call task, 1
|
||||||
|
func.apply func, args
|
||||||
|
if window.MessageChannel
|
||||||
|
taskChannel = new MessageChannel()
|
||||||
|
taskChannel.port1.onmessage = execTask
|
||||||
|
->
|
||||||
|
taskQueue.push arguments
|
||||||
|
taskChannel.port2.postMessage null
|
||||||
|
else # XXX Firefox
|
||||||
|
->
|
||||||
|
taskQueue.push arguments
|
||||||
|
setTimeout execTask, 0
|
||||||
|
)()
|
||||||
globalEval: (code) ->
|
globalEval: (code) ->
|
||||||
script = $.el 'script',
|
script = $.el 'script',
|
||||||
textContent: code
|
textContent: code
|
||||||
@ -373,9 +393,9 @@ $.extend $,
|
|||||||
$.rm script
|
$.rm script
|
||||||
# http://mths.be/unsafewindow
|
# http://mths.be/unsafewindow
|
||||||
unsafeWindow: window.opera and window or unsafeWindow or (->
|
unsafeWindow: window.opera and window or unsafeWindow or (->
|
||||||
d.createElement 'p'
|
p = d.createElement 'p'
|
||||||
p.setAttribute 'onclick', 'return window'
|
p.setAttribute 'onclick', 'return window'
|
||||||
el.onclick()
|
p.onclick()
|
||||||
)()
|
)()
|
||||||
shortenFilename: (filename, isOP) ->
|
shortenFilename: (filename, isOP) ->
|
||||||
# FILENAME SHORTENING SCIENCE:
|
# FILENAME SHORTENING SCIENCE:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user