diff --git a/builds/4chan-X.user.js b/builds/4chan-X.user.js index 71277dcf5..bea416866 100644 --- a/builds/4chan-X.user.js +++ b/builds/4chan-X.user.js @@ -4428,21 +4428,28 @@ } }, embed: function(data) { - var embed, key, link, options, uid; + var embed, href, key, link, name, options, uid, value, _ref; key = data[0], uid = data[1], options = data[2], link = data[3]; + href = link.href; embed = $.el('a', { - name: uid, - option: options, className: 'embedder', href: 'javascript:;', textContent: '(embed)' }); - embed.dataset.service = key; - embed.dataset.originalurl = link.href; - $.addClass(link, "" + embed.dataset.service); + _ref = { + key: key, + href: href, + uid: uid, + options: options + }; + for (name in _ref) { + value = _ref[name]; + embed.dataset[name] = value; + } + $.addClass(link, "" + embed.dataset.key); $.on(embed, 'click', Linkify.cb.toggle); - return $.after(link, [$.tn(' '), embed]); + $.after(link, [$.tn(' '), embed]); }, title: function(data) { var err, key, link, options, service, title, titles, uid; @@ -4488,23 +4495,24 @@ embed: function(a) { var el, style, type; - el = (type = Linkify.types[a.dataset.service]).el.call(a); + el = (type = Linkify.types[a.dataset.key]).el.call(a); el.style.cssText = (style = type.style) ? style : "border: 0; width: 640px; height: 390px"; a.textContent = '(unembed)'; return el; }, unembed: function(a) { - var el, url; + var el, href; + href = a.dataset.href; el = $.el('a', { rel: 'nofollow noreferrer', target: 'blank', className: 'linkify', - href: url = a.dataset.originalurl, - textContent: a.dataset.title || url + href: href, + textContent: a.dataset.title || href }); a.textContent = '(embed)'; - $.addClass(el, "" + a.dataset.service); + $.addClass(el, "" + a.dataset.key); return el; }, title: function(data) { @@ -4538,7 +4546,7 @@ return $.el('audio', { controls: 'controls', preload: 'auto', - src: this.name + src: this.dataset.uid }); } }, @@ -4548,7 +4556,7 @@ var div; return div = $.el('iframe', { - src: "http://www.purplegene.com/script?url=https://gist.github.com/" + this.name + ".js" + src: "http://www.purplegene.com/script?url=https://gist.github.com/" + this.dataset.uid + ".js" }); }, title: { @@ -4572,7 +4580,7 @@ style: 'border: 0; width: auto; height: auto;', el: function() { return $.el('div', { - innerHTML: "" + innerHTML: "" }); } }, @@ -4580,7 +4588,7 @@ regExp: /.*(?:paste.installgentoo.com\/view\/)([0-9a-z_]+)/, el: function() { return $.el('iframe', { - src: "http://paste.installgentoo.com/view/embed/" + this.name + src: "http://paste.installgentoo.com/view/embed/" + this.dataset.uid }); } }, @@ -4588,7 +4596,7 @@ regExp: /.*(?:liveleak.com\/view.+i=)([0-9a-z_]+)/, el: function() { return $.el('object', { - innerHTML: "" + innerHTML: "" }); } }, @@ -4598,7 +4606,7 @@ var div; return div = $.el('iframe', { - src: "http://pastebin.com/embed_iframe.php?i=" + this.name + src: "http://pastebin.com/embed_iframe.php?i=" + this.dataset.uid }); } }, @@ -4612,7 +4620,7 @@ className: "soundcloud", name: "soundcloud" }); - $.ajax("//soundcloud.com/oembed?show_artwork=false&&maxwidth=500px&show_comments=false&format=json&url=https://www.soundcloud.com/" + this.name, { + $.ajax("//soundcloud.com/oembed?show_artwork=false&&maxwidth=500px&show_comments=false&format=json&url=https://www.soundcloud.com/" + this.dataset.uid, { div: div, onloadend: function() { return this.div.innerHTML = JSON.parse(this.responseText).html; @@ -4634,7 +4642,7 @@ style: 'border: 0; width: 150px; height: 45px;', el: function() { return $.el('object', { - innerHTML: "" + innerHTML: "" }); } }, @@ -4642,7 +4650,7 @@ regExp: /.*(?:vimeo.com\/)([^#\&\?]*).*/, el: function() { return $.el('iframe', { - src: "//player.vimeo.com/video/" + this.name + "?wmode=opaque" + src: "//player.vimeo.com/video/" + this.dataset.uid + "?wmode=opaque" }); }, title: { @@ -4659,7 +4667,7 @@ style: 'border: none; width: 500px; height: 500px;', el: function() { return $.el('iframe', { - src: "https://vine.co/" + this.name + "/card" + src: "https://vine.co/" + this.dataset.uid + "/card" }); } }, @@ -4667,7 +4675,7 @@ regExp: /.*(?:youtu.be\/|youtube.*v=|youtube.*\/embed\/|youtube.*\/v\/|youtube.*videos\/)([^#\&\?]*)\??(t\=.*)?/, el: function() { return $.el('iframe', { - src: "//www.youtube.com/embed/" + this.name + (this.option ? '#' + this.option : '') + "?wmode=opaque" + src: "//www.youtube.com/embed/" + this.dataset.uid + (this.dataset.option ? '#' + this.dataset.option : '') + "?wmode=opaque" }); }, title: { diff --git a/builds/crx/script.js b/builds/crx/script.js index 7fe3cdbf8..a41e296df 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -4433,21 +4433,28 @@ } }, embed: function(data) { - var embed, key, link, options, uid; + var embed, href, key, link, name, options, uid, value, _ref; key = data[0], uid = data[1], options = data[2], link = data[3]; + href = link.href; embed = $.el('a', { - name: uid, - option: options, className: 'embedder', href: 'javascript:;', textContent: '(embed)' }); - embed.dataset.service = key; - embed.dataset.originalurl = link.href; - $.addClass(link, "" + embed.dataset.service); + _ref = { + key: key, + href: href, + uid: uid, + options: options + }; + for (name in _ref) { + value = _ref[name]; + embed.dataset[name] = value; + } + $.addClass(link, "" + embed.dataset.key); $.on(embed, 'click', Linkify.cb.toggle); - return $.after(link, [$.tn(' '), embed]); + $.after(link, [$.tn(' '), embed]); }, title: function(data) { var err, key, link, options, service, title, titles, uid; @@ -4493,23 +4500,24 @@ embed: function(a) { var el, style, type; - el = (type = Linkify.types[a.dataset.service]).el.call(a); + el = (type = Linkify.types[a.dataset.key]).el.call(a); el.style.cssText = (style = type.style) ? style : "border: 0; width: 640px; height: 390px"; a.textContent = '(unembed)'; return el; }, unembed: function(a) { - var el, url; + var el, href; + href = a.dataset.href; el = $.el('a', { rel: 'nofollow noreferrer', target: 'blank', className: 'linkify', - href: url = a.dataset.originalurl, - textContent: a.dataset.title || url + href: href, + textContent: a.dataset.title || href }); a.textContent = '(embed)'; - $.addClass(el, "" + a.dataset.service); + $.addClass(el, "" + a.dataset.key); return el; }, title: function(data) { @@ -4543,7 +4551,7 @@ return $.el('audio', { controls: 'controls', preload: 'auto', - src: this.name + src: this.dataset.uid }); } }, @@ -4553,7 +4561,7 @@ var div; return div = $.el('iframe', { - src: "http://www.purplegene.com/script?url=https://gist.github.com/" + this.name + ".js" + src: "http://www.purplegene.com/script?url=https://gist.github.com/" + this.dataset.uid + ".js" }); }, title: { @@ -4577,7 +4585,7 @@ style: 'border: 0; width: auto; height: auto;', el: function() { return $.el('div', { - innerHTML: "" + innerHTML: "" }); } }, @@ -4585,7 +4593,7 @@ regExp: /.*(?:paste.installgentoo.com\/view\/)([0-9a-z_]+)/, el: function() { return $.el('iframe', { - src: "http://paste.installgentoo.com/view/embed/" + this.name + src: "http://paste.installgentoo.com/view/embed/" + this.dataset.uid }); } }, @@ -4593,7 +4601,7 @@ regExp: /.*(?:liveleak.com\/view.+i=)([0-9a-z_]+)/, el: function() { return $.el('object', { - innerHTML: "" + innerHTML: "" }); } }, @@ -4603,7 +4611,7 @@ var div; return div = $.el('iframe', { - src: "http://pastebin.com/embed_iframe.php?i=" + this.name + src: "http://pastebin.com/embed_iframe.php?i=" + this.dataset.uid }); } }, @@ -4617,7 +4625,7 @@ className: "soundcloud", name: "soundcloud" }); - $.ajax("//soundcloud.com/oembed?show_artwork=false&&maxwidth=500px&show_comments=false&format=json&url=https://www.soundcloud.com/" + this.name, { + $.ajax("//soundcloud.com/oembed?show_artwork=false&&maxwidth=500px&show_comments=false&format=json&url=https://www.soundcloud.com/" + this.dataset.uid, { div: div, onloadend: function() { return this.div.innerHTML = JSON.parse(this.responseText).html; @@ -4639,7 +4647,7 @@ style: 'border: 0; width: 150px; height: 45px;', el: function() { return $.el('object', { - innerHTML: "" + innerHTML: "" }); } }, @@ -4647,7 +4655,7 @@ regExp: /.*(?:vimeo.com\/)([^#\&\?]*).*/, el: function() { return $.el('iframe', { - src: "//player.vimeo.com/video/" + this.name + "?wmode=opaque" + src: "//player.vimeo.com/video/" + this.dataset.uid + "?wmode=opaque" }); }, title: { @@ -4664,7 +4672,7 @@ style: 'border: none; width: 500px; height: 500px;', el: function() { return $.el('iframe', { - src: "https://vine.co/" + this.name + "/card" + src: "https://vine.co/" + this.dataset.uid + "/card" }); } }, @@ -4672,7 +4680,7 @@ regExp: /.*(?:youtu.be\/|youtube.*v=|youtube.*\/embed\/|youtube.*\/v\/|youtube.*videos\/)([^#\&\?]*)\??(t\=.*)?/, el: function() { return $.el('iframe', { - src: "//www.youtube.com/embed/" + this.name + (this.option ? '#' + this.option : '') + "?wmode=opaque" + src: "//www.youtube.com/embed/" + this.dataset.uid + (this.dataset.option ? '#' + this.dataset.option : '') + "?wmode=opaque" }); }, title: { diff --git a/src/Linkification/Linkify.coffee b/src/Linkification/Linkify.coffee index 48dbb705a..34f46a4f9 100644 --- a/src/Linkification/Linkify.coffee +++ b/src/Linkification/Linkify.coffee @@ -137,20 +137,20 @@ Linkify = embed: (data) -> [key, uid, options, link] = data + href = link.href embed = $.el 'a', - name: uid - option: options className: 'embedder' href: 'javascript:;' textContent: '(embed)' - embed.dataset.service = key - embed.dataset.originalurl = link.href + for name, value of {key, href, uid, options} + embed.dataset[name] = value - $.addClass link, "#{embed.dataset.service}" + $.addClass link, "#{embed.dataset.key}" $.on embed, 'click', Linkify.cb.toggle $.after link, [$.tn(' '), embed] + return title: (data) -> [key, uid, options, link] = data @@ -190,7 +190,7 @@ Linkify = embed: (a) -> # We create an element to embed - el = (type = Linkify.types[a.dataset.service]).el.call a + el = (type = Linkify.types[a.dataset.key]).el.call a # Set style values. el.style.cssText = if style = type.style @@ -204,15 +204,16 @@ Linkify = unembed: (a) -> # Recreate the original link. + {href} = a.dataset el = $.el 'a', rel: 'nofollow noreferrer' target: 'blank' className: 'linkify' - href: url = a.dataset.originalurl - textContent: a.dataset.title or url + href: href + textContent: a.dataset.title or href a.textContent = '(embed)' - $.addClass el, "#{a.dataset.service}" + $.addClass el, "#{a.dataset.key}" return el @@ -239,14 +240,14 @@ Linkify = $.el 'audio', controls: 'controls' preload: 'auto' - src: @name + src: @dataset.uid gist: regExp: /.*(?:gist.github.com.*\/)([^\/][^\/]*)$/ el: -> div = $.el 'iframe', # Github doesn't allow embedding straight from the site, so we use an external site to bypass that. - src: "http://www.purplegene.com/script?url=https://gist.github.com/#{@name}.js" + src: "http://www.purplegene.com/script?url=https://gist.github.com/#{@dataset.uid}.js" title: api: (uid) -> "https://api.github.com/gists/#{uid}" text: -> @@ -258,25 +259,25 @@ Linkify = style: 'border: 0; width: auto; height: auto;' el: -> $.el 'div', - innerHTML: "" + innerHTML: "" InstallGentoo: regExp: /.*(?:paste.installgentoo.com\/view\/)([0-9a-z_]+)/ el: -> $.el 'iframe', - src: "http://paste.installgentoo.com/view/embed/#{@name}" + src: "http://paste.installgentoo.com/view/embed/#{@dataset.uid}" LiveLeak: regExp: /.*(?:liveleak.com\/view.+i=)([0-9a-z_]+)/ el: -> $.el 'object', - innerHTML: "" + innerHTML: "" pastebin: regExp: /.*(?:pastebin.com\/(?!u\/))([^#\&\?]*).*/ el: -> div = $.el 'iframe', - src: "http://pastebin.com/embed_iframe.php?i=#{@name}" + src: "http://pastebin.com/embed_iframe.php?i=#{@dataset.uid}" SoundCloud: regExp: /.*(?:soundcloud.com\/|snd.sc\/)([^#\&\?]*).*/ @@ -286,7 +287,7 @@ Linkify = className: "soundcloud" name: "soundcloud" $.ajax( - "//soundcloud.com/oembed?show_artwork=false&&maxwidth=500px&show_comments=false&format=json&url=https://www.soundcloud.com/#{@name}" + "//soundcloud.com/oembed?show_artwork=false&&maxwidth=500px&show_comments=false&format=json&url=https://www.soundcloud.com/#{@dataset.uid}" div: div onloadend: -> @div.innerHTML = JSON.parse(@responseText).html @@ -315,13 +316,13 @@ Linkify = style: 'border: 0; width: 150px; height: 45px;' el: -> $.el 'object', - innerHTML: "" + innerHTML: "" Vimeo: regExp: /.*(?:vimeo.com\/)([^#\&\?]*).*/ el: -> $.el 'iframe', - src: "//player.vimeo.com/video/#{@name}?wmode=opaque" + src: "//player.vimeo.com/video/#{@dataset.uid}?wmode=opaque" title: api: (uid) -> "https://vimeo.com/api/oembed.json?url=http://vimeo.com/#{uid}" text: -> JSON.parse(@responseText).title @@ -331,13 +332,13 @@ Linkify = style: 'border: none; width: 500px; height: 500px;' el: -> $.el 'iframe', - src: "https://vine.co/#{@name}/card" + src: "https://vine.co/#{@dataset.uid}/card" YouTube: regExp: /.*(?:youtu.be\/|youtube.*v=|youtube.*\/embed\/|youtube.*\/v\/|youtube.*videos\/)([^#\&\?]*)\??(t\=.*)?/ el: -> $.el 'iframe', - src: "//www.youtube.com/embed/#{@name}#{if @option then '#' + @option else ''}?wmode=opaque" + src: "//www.youtube.com/embed/#{@dataset.uid}#{if @dataset.option then '#' + @dataset.option else ''}?wmode=opaque" title: api: (uid) -> "https://gdata.youtube.com/feeds/api/videos/#{uid}?alt=json&fields=title/text(),yt:noembed,app:control/yt:state/@reasonCode" text: -> JSON.parse(@responseText).entry.title.$t \ No newline at end of file