forked from gkovacs/foreign-manga-reader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scriptUtils.coffee~
40 lines (34 loc) · 1.33 KB
/
scriptUtils.coffee~
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
root = exports ? this
#exposeFunction = root.exposeFunction = (fname, callback) ->
# return (args...) ->
# #executeInPage(() ->
# # callback(f(args...))
# #)
# chrome.extension.sendMessage({'executeHere': {'function': fname.toString, 'arglist': args}})
callOnceElementAvailable = root.callOnceElementAvailable = (element, callback) ->
if $(element).length > 0
callback()
else
setTimeout(() ->
callOnceElementAvailable(element, callback)
, 300)
callOnceObjectAvailable = root.callOnceObjectAvailable = (objectname, callback) ->
if window[objectname]?
callback()
else
setTimeout(() ->
callOnceObjectAvailable(objectname, callback)
, 300)
executeInPage = root.executeInPage = (myCode) ->
#console.log $('<script>').text('(' + myCode + ')();')
#$('head').append $('<script>').text('(' + myCode + ')();')
scriptTag = document.createElement('script')
scriptTag.type = 'text/javascript'
scriptTag.innerHTML = '(' + myCode + ')();'
document.documentElement.appendChild(scriptTag)
assignVariable = root.assignVariable = (variableName, codeValue) ->
codeValueAsText = codeValue.toString()
scriptTag = document.createElement('script')
scriptTag.type = 'text/javascript'
scriptTag.innerHTML = variableName + ' = ' + codeValueAsText + ';'
document.documentElement.appendChild(scriptTag)