From 6cf7373b938cf8d4841198584d7b709b45f27396 Mon Sep 17 00:00:00 2001 From: Mayhem Date: Mon, 5 Aug 2013 21:19:20 +0200 Subject: [PATCH 1/5] Fix #1162. --- src/General/Build.coffee | 52 +++++++++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 17 deletions(-) diff --git a/src/General/Build.coffee b/src/General/Build.coffee index 713e0586a..0d39bc343 100644 --- a/src/General/Build.coffee +++ b/src/General/Build.coffee @@ -27,6 +27,7 @@ Build = date: data.now dateUTC: data.time comment: data.com + capReps: data.capcode_replies # thread status isSticky: !!data.sticky isClosed: !!data.closed @@ -54,7 +55,7 @@ Build = postID, threadID, boardID name, capcode, tripcode, uniqueID, email, subject, flagCode, flagName, date, dateUTC isSticky, isClosed - comment + comment, capReps file } = o isOP = postID is threadID @@ -172,22 +173,39 @@ Build = else fileHTML = '' - tripcode = - if tripcode - " #{tripcode}" - else - '' + tripcode = if tripcode + " #{tripcode}" + else + '' - sticky = - if isSticky - " Sticky" - else - '' - closed = - if isClosed - " Closed" - else - '' + sticky = if isSticky + " Sticky" + else + '' + closed = if isClosed + " Closed" + else + '' + + capcodeReplies = '' + if capReps + generateCapcodeReplies = (capcodeType, array) -> + "#{ + switch capcodeType + when 'admin' + 'Administrator' + when 'mod' + 'Moderator' + when 'developer' + 'Developer' + } Repl#{if array.length > 1 then 'ies' else 'y'}: #{ + array.map (ID) -> + ">>#{ID}" + .join ' ' + }
" + for capcodeType, array of capReps + capcodeReplies += generateCapcodeReplies capcodeType, array + capcodeReplies = "

#{capcodeReplies}" container = $.el 'div', id: "pc#{postID}" @@ -241,7 +259,7 @@ Build = (if isOP then '' else fileHTML) + - "
#{comment or ''}
" + + "
#{comment or ''}#{capcodeReplies}
" + '' From 250323d304dece37c55fffdd5922fbe165318f14 Mon Sep 17 00:00:00 2001 From: Zixaphir Date: Mon, 5 Aug 2013 12:19:26 -0700 Subject: [PATCH 2/5] Vine --- builds/4chan-X.user.js | 155 ++++++++++++++++--------------- builds/crx/script.js | 155 ++++++++++++++++--------------- src/Linkification/Linkify.coffee | 123 ++++++++++++++---------- 3 files changed, 236 insertions(+), 197 deletions(-) diff --git a/builds/4chan-X.user.js b/builds/4chan-X.user.js index f5ce94ae5..71277dcf5 100644 --- a/builds/4chan-X.user.js +++ b/builds/4chan-X.user.js @@ -4532,55 +4532,6 @@ } }, types: { - YouTube: { - 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" - }); - }, - title: { - api: function(uid) { - return "https://gdata.youtube.com/feeds/api/videos/" + uid + "?alt=json&fields=title/text(),yt:noembed,app:control/yt:state/@reasonCode"; - }, - text: function() { - return JSON.parse(this.responseText).entry.title.$t; - } - } - }, - Vocaroo: { - regExp: /.*(?:vocaroo.com\/)([^#\&\?]*).*/, - style: 'border: 0; width: 150px; height: 45px;', - el: function() { - return $.el('object', { - innerHTML: "" - }); - } - }, - Vimeo: { - regExp: /.*(?:vimeo.com\/)([^#\&\?]*).*/, - el: function() { - return $.el('iframe', { - src: "//player.vimeo.com/video/" + this.name + "?wmode=opaque" - }); - }, - title: { - api: function(uid) { - return "https://vimeo.com/api/oembed.json?url=http://vimeo.com/" + uid; - }, - text: function() { - return JSON.parse(this.responseText).title; - } - } - }, - LiveLeak: { - regExp: /.*(?:liveleak.com\/view.+i=)([0-9a-z_]+)/, - el: function() { - return $.el('object', { - innerHTML: "" - }); - } - }, audio: { regExp: /(.*\.(mp3|ogg|wav))$/, el: function() { @@ -4591,6 +4542,31 @@ }); } }, + gist: { + regExp: /.*(?:gist.github.com.*\/)([^\/][^\/]*)$/, + el: function() { + var div; + + return div = $.el('iframe', { + src: "http://www.purplegene.com/script?url=https://gist.github.com/" + this.name + ".js" + }); + }, + title: { + api: function(uid) { + return "https://api.github.com/gists/" + uid; + }, + text: function() { + var file, response; + + response = JSON.parse(this.responseText).files; + for (file in response) { + if (response.hasOwnProperty(file)) { + return file; + } + } + } + } + }, image: { regExp: /(http|www).*\.(gif|png|jpg|jpeg|bmp)$/, style: 'border: 0; width: auto; height: auto;', @@ -4600,6 +4576,32 @@ }); } }, + InstallGentoo: { + regExp: /.*(?:paste.installgentoo.com\/view\/)([0-9a-z_]+)/, + el: function() { + return $.el('iframe', { + src: "http://paste.installgentoo.com/view/embed/" + this.name + }); + } + }, + LiveLeak: { + regExp: /.*(?:liveleak.com\/view.+i=)([0-9a-z_]+)/, + el: function() { + return $.el('object', { + innerHTML: "" + }); + } + }, + pastebin: { + regExp: /.*(?:pastebin.com\/(?!u\/))([^#\&\?]*).*/, + el: function() { + var div; + + return div = $.el('iframe', { + src: "http://pastebin.com/embed_iframe.php?i=" + this.name + }); + } + }, SoundCloud: { regExp: /.*(?:soundcloud.com\/|snd.sc\/)([^#\&\?]*).*/, style: 'height: auto; width: 500px; display: inline-block;', @@ -4627,48 +4629,55 @@ } } }, - pastebin: { - regExp: /.*(?:pastebin.com\/(?!u\/))([^#\&\?]*).*/, + Vocaroo: { + regExp: /.*(?:vocaroo.com\/)([^#\&\?]*).*/, + style: 'border: 0; width: 150px; height: 45px;', el: function() { - var div; - - return div = $.el('iframe', { - src: "http://pastebin.com/embed_iframe.php?i=" + this.name + return $.el('object', { + innerHTML: "" }); } }, - gist: { - regExp: /.*(?:gist.github.com.*\/)([^\/][^\/]*)$/, + Vimeo: { + regExp: /.*(?:vimeo.com\/)([^#\&\?]*).*/, el: function() { - var div; - - return div = $.el('iframe', { - src: "http://www.purplegene.com/script?url=https://gist.github.com/" + this.name + ".js" + return $.el('iframe', { + src: "//player.vimeo.com/video/" + this.name + "?wmode=opaque" }); }, title: { api: function(uid) { - return "https://api.github.com/gists/" + uid; + return "https://vimeo.com/api/oembed.json?url=http://vimeo.com/" + uid; }, text: function() { - var file, response; - - response = JSON.parse(this.responseText).files; - for (file in response) { - if (response.hasOwnProperty(file)) { - return file; - } - } + return JSON.parse(this.responseText).title; } } }, - InstallGentoo: { - regExp: /.*(?:paste.installgentoo.com\/view\/)([0-9a-z_]+)/, + Vine: { + regExp: /.*(?:vine.co\/)([^#\&\?]*).*/, + style: 'border: none; width: 500px; height: 500px;', el: function() { return $.el('iframe', { - src: "http://paste.installgentoo.com/view/embed/" + this.name + src: "https://vine.co/" + this.name + "/card" }); } + }, + YouTube: { + 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" + }); + }, + title: { + api: function(uid) { + return "https://gdata.youtube.com/feeds/api/videos/" + uid + "?alt=json&fields=title/text(),yt:noembed,app:control/yt:state/@reasonCode"; + }, + text: function() { + return JSON.parse(this.responseText).entry.title.$t; + } + } } } }; diff --git a/builds/crx/script.js b/builds/crx/script.js index 8fd0d325e..7fe3cdbf8 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -4537,55 +4537,6 @@ } }, types: { - YouTube: { - 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" - }); - }, - title: { - api: function(uid) { - return "https://gdata.youtube.com/feeds/api/videos/" + uid + "?alt=json&fields=title/text(),yt:noembed,app:control/yt:state/@reasonCode"; - }, - text: function() { - return JSON.parse(this.responseText).entry.title.$t; - } - } - }, - Vocaroo: { - regExp: /.*(?:vocaroo.com\/)([^#\&\?]*).*/, - style: 'border: 0; width: 150px; height: 45px;', - el: function() { - return $.el('object', { - innerHTML: "" - }); - } - }, - Vimeo: { - regExp: /.*(?:vimeo.com\/)([^#\&\?]*).*/, - el: function() { - return $.el('iframe', { - src: "//player.vimeo.com/video/" + this.name + "?wmode=opaque" - }); - }, - title: { - api: function(uid) { - return "https://vimeo.com/api/oembed.json?url=http://vimeo.com/" + uid; - }, - text: function() { - return JSON.parse(this.responseText).title; - } - } - }, - LiveLeak: { - regExp: /.*(?:liveleak.com\/view.+i=)([0-9a-z_]+)/, - el: function() { - return $.el('object', { - innerHTML: "" - }); - } - }, audio: { regExp: /(.*\.(mp3|ogg|wav))$/, el: function() { @@ -4596,6 +4547,31 @@ }); } }, + gist: { + regExp: /.*(?:gist.github.com.*\/)([^\/][^\/]*)$/, + el: function() { + var div; + + return div = $.el('iframe', { + src: "http://www.purplegene.com/script?url=https://gist.github.com/" + this.name + ".js" + }); + }, + title: { + api: function(uid) { + return "https://api.github.com/gists/" + uid; + }, + text: function() { + var file, response; + + response = JSON.parse(this.responseText).files; + for (file in response) { + if (response.hasOwnProperty(file)) { + return file; + } + } + } + } + }, image: { regExp: /(http|www).*\.(gif|png|jpg|jpeg|bmp)$/, style: 'border: 0; width: auto; height: auto;', @@ -4605,6 +4581,32 @@ }); } }, + InstallGentoo: { + regExp: /.*(?:paste.installgentoo.com\/view\/)([0-9a-z_]+)/, + el: function() { + return $.el('iframe', { + src: "http://paste.installgentoo.com/view/embed/" + this.name + }); + } + }, + LiveLeak: { + regExp: /.*(?:liveleak.com\/view.+i=)([0-9a-z_]+)/, + el: function() { + return $.el('object', { + innerHTML: "" + }); + } + }, + pastebin: { + regExp: /.*(?:pastebin.com\/(?!u\/))([^#\&\?]*).*/, + el: function() { + var div; + + return div = $.el('iframe', { + src: "http://pastebin.com/embed_iframe.php?i=" + this.name + }); + } + }, SoundCloud: { regExp: /.*(?:soundcloud.com\/|snd.sc\/)([^#\&\?]*).*/, style: 'height: auto; width: 500px; display: inline-block;', @@ -4632,48 +4634,55 @@ } } }, - pastebin: { - regExp: /.*(?:pastebin.com\/(?!u\/))([^#\&\?]*).*/, + Vocaroo: { + regExp: /.*(?:vocaroo.com\/)([^#\&\?]*).*/, + style: 'border: 0; width: 150px; height: 45px;', el: function() { - var div; - - return div = $.el('iframe', { - src: "http://pastebin.com/embed_iframe.php?i=" + this.name + return $.el('object', { + innerHTML: "" }); } }, - gist: { - regExp: /.*(?:gist.github.com.*\/)([^\/][^\/]*)$/, + Vimeo: { + regExp: /.*(?:vimeo.com\/)([^#\&\?]*).*/, el: function() { - var div; - - return div = $.el('iframe', { - src: "http://www.purplegene.com/script?url=https://gist.github.com/" + this.name + ".js" + return $.el('iframe', { + src: "//player.vimeo.com/video/" + this.name + "?wmode=opaque" }); }, title: { api: function(uid) { - return "https://api.github.com/gists/" + uid; + return "https://vimeo.com/api/oembed.json?url=http://vimeo.com/" + uid; }, text: function() { - var file, response; - - response = JSON.parse(this.responseText).files; - for (file in response) { - if (response.hasOwnProperty(file)) { - return file; - } - } + return JSON.parse(this.responseText).title; } } }, - InstallGentoo: { - regExp: /.*(?:paste.installgentoo.com\/view\/)([0-9a-z_]+)/, + Vine: { + regExp: /.*(?:vine.co\/)([^#\&\?]*).*/, + style: 'border: none; width: 500px; height: 500px;', el: function() { return $.el('iframe', { - src: "http://paste.installgentoo.com/view/embed/" + this.name + src: "https://vine.co/" + this.name + "/card" }); } + }, + YouTube: { + 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" + }); + }, + title: { + api: function(uid) { + return "https://gdata.youtube.com/feeds/api/videos/" + uid + "?alt=json&fields=title/text(),yt:noembed,app:control/yt:state/@reasonCode"; + }, + text: function() { + return JSON.parse(this.responseText).entry.title.$t; + } + } } } }; diff --git a/src/Linkification/Linkify.coffee b/src/Linkification/Linkify.coffee index c32ec484e..48dbb705a 100644 --- a/src/Linkification/Linkify.coffee +++ b/src/Linkification/Linkify.coffee @@ -233,52 +233,51 @@ Linkify = "[#{key}] #{@status}'d" types: - 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" - 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 - - Vocaroo: - regExp: /.*(?:vocaroo.com\/)([^#\&\?]*).*/ - style: 'border: 0; width: 150px; height: 45px;' - el: -> - $.el 'object', - innerHTML: "" - - Vimeo: - regExp: /.*(?:vimeo.com\/)([^#\&\?]*).*/ - el: -> - $.el 'iframe', - src: "//player.vimeo.com/video/#{@name}?wmode=opaque" - title: - api: (uid) -> "https://vimeo.com/api/oembed.json?url=http://vimeo.com/#{uid}" - text: -> JSON.parse(@responseText).title - - LiveLeak: - regExp: /.*(?:liveleak.com\/view.+i=)([0-9a-z_]+)/ - el: -> - $.el 'object', - innerHTML: "" - audio: - regExp: /(.*\.(mp3|ogg|wav))$/ + regExp: /(.*\.(mp3|ogg|wav))$/ el: -> $.el 'audio', controls: 'controls' preload: 'auto' src: @name + 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" + title: + api: (uid) -> "https://api.github.com/gists/#{uid}" + text: -> + response = JSON.parse(@responseText).files + return file for file of response when response.hasOwnProperty file + image: - regExp: /(http|www).*\.(gif|png|jpg|jpeg|bmp)$/ + regExp: /(http|www).*\.(gif|png|jpg|jpeg|bmp)$/ style: 'border: 0; width: auto; height: auto;' el: -> $.el 'div', innerHTML: "" + InstallGentoo: + regExp: /.*(?:paste.installgentoo.com\/view\/)([0-9a-z_]+)/ + el: -> + $.el 'iframe', + src: "http://paste.installgentoo.com/view/embed/#{@name}" + + LiveLeak: + regExp: /.*(?:liveleak.com\/view.+i=)([0-9a-z_]+)/ + el: -> + $.el 'object', + innerHTML: "" + + pastebin: + regExp: /.*(?:pastebin.com\/(?!u\/))([^#\&\?]*).*/ + el: -> + div = $.el 'iframe', + src: "http://pastebin.com/embed_iframe.php?i=#{@name}" + SoundCloud: regExp: /.*(?:soundcloud.com\/|snd.sc\/)([^#\&\?]*).*/ style: 'height: auto; width: 500px; display: inline-block;' @@ -297,26 +296,48 @@ Linkify = api: (uid) -> "//soundcloud.com/oembed?show_artwork=false&&maxwidth=500px&show_comments=false&format=json&url=https://www.soundcloud.com/#{uid}" text: -> JSON.parse(@responseText).title - pastebin: - regExp: /.*(?:pastebin.com\/(?!u\/))([^#\&\?]*).*/ - el: -> - div = $.el 'iframe', - src: "http://pastebin.com/embed_iframe.php?i=#{@name}" +# WIP +# +# TwitchTV: +# regExp: /twitch\.tv\/(\w+)\/(?:b\/)?(\d+)/i +# style: "border: none; width: 640px; height: 360px;" +# el: -> +# [_, channel, archive] = @result +# el = $.el 'object', +# data: 'http://www.twitch.tv/widgets/archive_embed_player.swf' +# innerHTML: """ +# +# +#""" - gist: - regExp: /.*(?:gist.github.com.*\/)([^\/][^\/]*)$/ + Vocaroo: + regExp: /.*(?:vocaroo.com\/)([^#\&\?]*).*/ + style: 'border: 0; width: 150px; height: 45px;' 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" - title: - api: (uid) -> "https://api.github.com/gists/#{uid}" - text: -> - response = JSON.parse(@responseText).files - return file for file of response when response.hasOwnProperty file + $.el 'object', + innerHTML: "" - InstallGentoo: - regExp: /.*(?:paste.installgentoo.com\/view\/)([0-9a-z_]+)/ + Vimeo: + regExp: /.*(?:vimeo.com\/)([^#\&\?]*).*/ el: -> $.el 'iframe', - src: "http://paste.installgentoo.com/view/embed/#{@name}" \ No newline at end of file + src: "//player.vimeo.com/video/#{@name}?wmode=opaque" + title: + api: (uid) -> "https://vimeo.com/api/oembed.json?url=http://vimeo.com/#{uid}" + text: -> JSON.parse(@responseText).title + + Vine: + regExp: /.*(?:vine.co\/)([^#\&\?]*).*/ + style: 'border: none; width: 500px; height: 500px;' + el: -> + $.el 'iframe', + src: "https://vine.co/#{@name}/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" + 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 From c44014b19ec9dcc4d16869ec9c22ee416b7ce179 Mon Sep 17 00:00:00 2001 From: Zixaphir Date: Mon, 5 Aug 2013 13:01:44 -0700 Subject: [PATCH 3/5] Lets stop filling syntactical fields with non-meta-data --- builds/4chan-X.user.js | 54 ++++++++++++++++++-------------- builds/crx/script.js | 54 ++++++++++++++++++-------------- src/Linkification/Linkify.coffee | 41 ++++++++++++------------ 3 files changed, 83 insertions(+), 66 deletions(-) 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 From d5553cf5fd97cfa7acd0268b22d01edd989744d6 Mon Sep 17 00:00:00 2001 From: Zixaphir Date: Mon, 5 Aug 2013 14:05:29 -0700 Subject: [PATCH 4/5] TwitchTV embedding (live and archive) --- builds/4chan-X.user.js | 31 +++++++++++++++++---- builds/crx/script.js | 31 +++++++++++++++++---- src/Linkification/Linkify.coffee | 46 ++++++++++++++++++++------------ 3 files changed, 81 insertions(+), 27 deletions(-) diff --git a/builds/4chan-X.user.js b/builds/4chan-X.user.js index bea416866..db60047f5 100644 --- a/builds/4chan-X.user.js +++ b/builds/4chan-X.user.js @@ -4328,6 +4328,9 @@ len = snapshot.snapshotLength; while (++i < len) { node = snapshot.snapshotItem(i); + if (node.parentElement.nodeName === "A") { + continue; + } data = node.data; if (Linkify.regString.test(data)) { Linkify.regString.lastIndex = 0; @@ -4360,7 +4363,7 @@ index = match.index; link = match[0]; len2 = index + link.length; - if (len - len2 === 0) { + if (len === len2) { break; } range = document.createRange(); @@ -4393,10 +4396,7 @@ } } if (range.collapsed) { - if (node.nodeName === 'WBR') { - node = node.previousSibling; - } - range.setEnd(node, node.length); + range.setEndAfter(node); } return Linkify.makeLink(range, post); }, @@ -4637,6 +4637,27 @@ } } }, + TwitchTV: { + regExp: /.*(?:twitch.tv\/)([^#\&\?]*).*/, + style: "border: none; width: 640px; height: 360px;", + el: function() { + var channel, chapter, result, _; + + if (result = /(\w+)\/(?:[a-z]\/)?(\d+)/i.exec(this.dataset.uid)) { + _ = result[0], channel = result[1], chapter = result[2]; + return $.el('object', { + data: 'http://www.twitch.tv/widgets/archive_embed_player.swf', + innerHTML: "\n" + }); + } else { + channel = (/(\w+)/.exec(this.dataset.uid))[0]; + return $.el('object', { + data: "http://www.twitch.tv/widgets/live_embed_player.swf?channel=" + channel, + innerHTML: "\n\n" + }); + } + } + }, Vocaroo: { regExp: /.*(?:vocaroo.com\/)([^#\&\?]*).*/, style: 'border: 0; width: 150px; height: 45px;', diff --git a/builds/crx/script.js b/builds/crx/script.js index a41e296df..aee40189e 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -4333,6 +4333,9 @@ len = snapshot.snapshotLength; while (++i < len) { node = snapshot.snapshotItem(i); + if (node.parentElement.nodeName === "A") { + continue; + } data = node.data; if (Linkify.regString.test(data)) { Linkify.regString.lastIndex = 0; @@ -4365,7 +4368,7 @@ index = match.index; link = match[0]; len2 = index + link.length; - if (len - len2 === 0) { + if (len === len2) { break; } range = document.createRange(); @@ -4398,10 +4401,7 @@ } } if (range.collapsed) { - if (node.nodeName === 'WBR') { - node = node.previousSibling; - } - range.setEnd(node, node.length); + range.setEndAfter(node); } return Linkify.makeLink(range, post); }, @@ -4642,6 +4642,27 @@ } } }, + TwitchTV: { + regExp: /.*(?:twitch.tv\/)([^#\&\?]*).*/, + style: "border: none; width: 640px; height: 360px;", + el: function() { + var channel, chapter, result, _; + + if (result = /(\w+)\/(?:[a-z]\/)?(\d+)/i.exec(this.dataset.uid)) { + _ = result[0], channel = result[1], chapter = result[2]; + return $.el('object', { + data: 'http://www.twitch.tv/widgets/archive_embed_player.swf', + innerHTML: "\n" + }); + } else { + channel = (/(\w+)/.exec(this.dataset.uid))[0]; + return $.el('object', { + data: "http://www.twitch.tv/widgets/live_embed_player.swf?channel=" + channel, + innerHTML: "\n\n" + }); + } + } + }, Vocaroo: { regExp: /.*(?:vocaroo.com\/)([^#\&\?]*).*/, style: 'border: 0; width: 150px; height: 45px;', diff --git a/src/Linkification/Linkify.coffee b/src/Linkification/Linkify.coffee index 34f46a4f9..ba46a0c58 100644 --- a/src/Linkification/Linkify.coffee +++ b/src/Linkification/Linkify.coffee @@ -44,6 +44,9 @@ Linkify = while ++i < len node = snapshot.snapshotItem i + + continue if node.parentElement.nodeName is "A" + data = node.data if Linkify.regString.test data @@ -69,7 +72,7 @@ Linkify = link = match[0] len2 = index + link.length - break if len - len2 is 0 + break if len is len2 range = document.createRange(); range.setStart node, index @@ -99,9 +102,7 @@ Linkify = range.setEnd node, result.index if range.collapsed - if node.nodeName is 'WBR' - node = node.previousSibling - range.setEnd node, node.length + range.setEndAfter node Linkify.makeLink range, post @@ -297,19 +298,30 @@ Linkify = api: (uid) -> "//soundcloud.com/oembed?show_artwork=false&&maxwidth=500px&show_comments=false&format=json&url=https://www.soundcloud.com/#{uid}" text: -> JSON.parse(@responseText).title -# WIP -# -# TwitchTV: -# regExp: /twitch\.tv\/(\w+)\/(?:b\/)?(\d+)/i -# style: "border: none; width: 640px; height: 360px;" -# el: -> -# [_, channel, archive] = @result -# el = $.el 'object', -# data: 'http://www.twitch.tv/widgets/archive_embed_player.swf' -# innerHTML: """ -# -# -#""" + TwitchTV: + regExp: /.*(?:twitch.tv\/)([^#\&\?]*).*/ + style: "border: none; width: 640px; height: 360px;" + el: -> + if result = /(\w+)\/(?:[a-z]\/)?(\d+)/i.exec @dataset.uid + [_, channel, chapter] = result + + $.el 'object', + data: 'http://www.twitch.tv/widgets/archive_embed_player.swf' + innerHTML: """ + + +""" + + else + channel = (/(\w+)/.exec @dataset.uid)[0] + + $.el 'object', + data: "http://www.twitch.tv/widgets/live_embed_player.swf?channel=#{channel}" + innerHTML: """ + + + +""" Vocaroo: regExp: /.*(?:vocaroo.com\/)([^#\&\?]*).*/ From b36cf54d83874270cff0e4c41e350b6322e523dd Mon Sep 17 00:00:00 2001 From: Mayhem Date: Mon, 5 Aug 2013 23:30:39 +0200 Subject: [PATCH 5/5] Make use of a few CoffeeScript filters. --- lib/$.coffee | 3 +-- src/General/Header.coffee | 3 +-- src/General/Post.coffee | 3 +-- src/General/Settings.coffee | 3 +-- src/Posting/QR.coffee | 4 +--- 5 files changed, 5 insertions(+), 11 deletions(-) diff --git a/lib/$.coffee b/lib/$.coffee index 811614b78..59e08cbbd 100644 --- a/lib/$.coffee +++ b/lib/$.coffee @@ -24,8 +24,7 @@ $.formData = (form) -> if form instanceof HTMLFormElement return new FormData form fd = new FormData() - for key, val of form - continue unless val + for key, val of form when val # XXX GM bug # if val instanceof Blob if val.size and val.name diff --git a/src/General/Header.coffee b/src/General/Header.coffee index 5ba74529f..ae98518ed 100644 --- a/src/General/Header.coffee +++ b/src/General/Header.coffee @@ -199,8 +199,7 @@ Header = '#boardNavDesktopFoot a[href*="boards.4chan.org"]' ].join ', ' path = if useCatalog then 'catalog' else '' - for a in as - continue if a.dataset.only + for a in as when not a.dataset.only a.pathname = "/#{a.pathname.split('/')[1]}/#{path}" return toggleCatalogLinks: -> diff --git a/src/General/Post.coffee b/src/General/Post.coffee index 6da7f33dc..1b890c2ec 100644 --- a/src/General/Post.coffee +++ b/src/General/Post.coffee @@ -167,8 +167,7 @@ class Post return if file # Get quotelinks/backlinks to this post # and paint them (Dead). - for quotelink in Get.allQuotelinksLinkingTo @ - continue if $.hasClass quotelink, 'deadlink' + for quotelink in Get.allQuotelinksLinkingTo @ when not $.hasClass quotelink, 'deadlink' $.add quotelink, $.tn '\u00A0(Dead)' $.addClass quotelink, 'deadlink' return diff --git a/src/General/Settings.coffee b/src/General/Settings.coffee index d0360db9e..660d78f78 100644 --- a/src/General/Settings.coffee +++ b/src/General/Settings.coffee @@ -277,8 +277,7 @@ Settings = '%board' else c - for key, val of Config.hotkeys - continue unless key of data.Conf + for key, val of Config.hotkeys when key of data.Conf data.Conf[key] = data.Conf[key].replace(/ctrl|alt|meta/g, (s) -> "#{s[0].toUpperCase()}#{s[1..]}").replace /(^|.+\+)[A-Z]$/g, (s) -> "Shift+#{s[0...-1]}#{s[-1..].toLowerCase()}" data.Conf.WatchedThreads = data.WatchedThreads diff --git a/src/Posting/QR.coffee b/src/Posting/QR.coffee index c77bdda1e..791e7ded0 100644 --- a/src/Posting/QR.coffee +++ b/src/Posting/QR.coffee @@ -176,9 +176,7 @@ QR = types[type].push val loadPersonas: (type, arr) -> list = $ "#list-#{type}", QR.nodes.el - for val in arr - # XXX Firefox displays empty