Make $.event work in Pale Moon with GM 3.x (no cloneInto function).

This commit is contained in:
ccd0 2015-05-28 02:26:12 -07:00
parent 7e192b6abc
commit 09dd35385e
2 changed files with 22 additions and 0 deletions

View File

@ -286,6 +286,7 @@ module.exports = (grunt) ->
GM_info: true
GM_xmlhttpRequest: true
cloneInto: true
unsafeWindow: true
chrome: true
script: 'tmp-<%= pkg.type %>/*.js'

View File

@ -219,6 +219,27 @@ $.event = (event, detail, root=d) ->
<% } %>
root.dispatchEvent new CustomEvent event, {bubbles: true, detail}
<% if (type === 'userscript') { %>
# XXX Make $.event work in Pale Moon with GM 3.x (no cloneInto function).
unless typeof cloneInto is 'function' or /^[01]\./.test(GM_info.version) or GM_info.scriptHandler # not FF30+, GM1-, or Tampermonkey
do ->
try
new CustomEvent 'x', detail: {}
catch err
unsafeConstructors =
Object: unsafeWindow.Object
Array: unsafeWindow.Array
clone = (obj) ->
if obj? and typeof obj is 'object' and (constructor = unsafeConstructors[obj.constructor.name])
obj2 = new constructor()
obj2[key] = clone val for key, val of obj
obj2
else
obj
$.event = (event, detail, root=d) ->
root.dispatchEvent new CustomEvent event, {bubbles: true, detail: clone detail}
<% } %>
$.open =
<% if (type === 'userscript') { %>
GM_openInTab