From c8c95a3cf06c1ddaaf71e77c32e1e37bc4ef2c22 Mon Sep 17 00:00:00 2001 From: WastedMeerkat Date: Tue, 19 Oct 2021 04:54:20 -0500 Subject: [PATCH 1/4] Fixed Twitch.tv embeds VOD embeds were broken due to a new URL scheme (legacy support maintained) Clip embed support has been added --- src/Linkification/Embedding.coffee | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Linkification/Embedding.coffee b/src/Linkification/Embedding.coffee index 912cc13d3..3dbd1ba1c 100644 --- a/src/Linkification/Embedding.coffee +++ b/src/Linkification/Embedding.coffee @@ -422,12 +422,15 @@ Embedding = text: (_) -> _.title , key: 'TwitchTV' - regExp: /^\w+:\/\/(?:www\.|secure\.)?twitch\.tv\/(\w[^#\&\?]*)/ + regExp: /^\w+:\/\/(?:www\.|secure\.|clips\.)?twitch\.tv\/(\w[^#\&\?]*)/ el: (a) -> - m = a.dataset.uid.match /(\w+)(?:\/v\/(\d+))?/ - url = "//player.twitch.tv/?#{if m[2] then "video=v#{m[2]}" else "channel=#{m[1]}"}&autoplay=false&parent=#{location.hostname}" - if (time = a.dataset.href.match /\bt=(\w+)/) - url += "&time=#{time[1]}" + if a.dataset.href.match(/^\w+:\/\/(www\.|secure\.|clips\.)?twitch\.tv/)[1] is 'clips.' + url = "//clips.twitch.tv/embed?clip=#{a.dataset.uid}&parent=#{location.hostname}" + else + m = a.dataset.uid.match /(\w+)(?:\/(?:v\/)?(\d+))?/ + url = "//player.twitch.tv/?#{if m[2] then "video=v#{m[2]}" else "channel=#{m[1]}"}&autoplay=false&parent=#{location.hostname}" + if (time = a.dataset.href.match /\bt=(\w+)/) + url += "&time=#{time[1]}" el = $.el 'iframe', src: url el.setAttribute "allowfullscreen", "true" From c298856c701a5080dd5ff0adf4457bd1dfcf23b6 Mon Sep 17 00:00:00 2001 From: WastedMeerkat Date: Tue, 19 Oct 2021 05:05:34 -0500 Subject: [PATCH 2/4] Made the regex check cooler --- src/Linkification/Embedding.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Linkification/Embedding.coffee b/src/Linkification/Embedding.coffee index 3dbd1ba1c..eaddffc3c 100644 --- a/src/Linkification/Embedding.coffee +++ b/src/Linkification/Embedding.coffee @@ -424,7 +424,7 @@ Embedding = key: 'TwitchTV' regExp: /^\w+:\/\/(?:www\.|secure\.|clips\.)?twitch\.tv\/(\w[^#\&\?]*)/ el: (a) -> - if a.dataset.href.match(/^\w+:\/\/(www\.|secure\.|clips\.)?twitch\.tv/)[1] is 'clips.' + if a.dataset.href.match(/^\w+:\/\/(?:(clips\.)|\w+\.)?twitch\.tv/)[1] url = "//clips.twitch.tv/embed?clip=#{a.dataset.uid}&parent=#{location.hostname}" else m = a.dataset.uid.match /(\w+)(?:\/(?:v\/)?(\d+))?/ From 38087bd3f7d304f5d3737e3be4513e7ecd37ed2f Mon Sep 17 00:00:00 2001 From: WastedMeerkat Date: Wed, 20 Oct 2021 17:58:04 -0500 Subject: [PATCH 3/4] Accomodate mobile Twitch links m.twitch.tv subdomain links now work, mobile clip links are a bit different so had to rework the regex again --- src/Linkification/Embedding.coffee | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Linkification/Embedding.coffee b/src/Linkification/Embedding.coffee index eaddffc3c..f220c73d2 100644 --- a/src/Linkification/Embedding.coffee +++ b/src/Linkification/Embedding.coffee @@ -422,10 +422,11 @@ Embedding = text: (_) -> _.title , key: 'TwitchTV' - regExp: /^\w+:\/\/(?:www\.|secure\.|clips\.)?twitch\.tv\/(\w[^#\&\?]*)/ + regExp: /^\w+:\/\/(?:www\.|secure\.|clips\.|m\.)?twitch\.tv\/(\w[^#\&\?]*)/ el: (a) -> - if a.dataset.href.match(/^\w+:\/\/(?:(clips\.)|\w+\.)?twitch\.tv/)[1] - url = "//clips.twitch.tv/embed?clip=#{a.dataset.uid}&parent=#{location.hostname}" + m = a.dataset.href.match /^\w+:\/\/(?:(clips\.)|\w+\.)?twitch\.tv\/(clip\/)?(\w[^#\&\?]*)/; + if m[1] or m[2] + url = "//clips.twitch.tv/embed?clip=#{m[3]}&parent=#{location.hostname}" else m = a.dataset.uid.match /(\w+)(?:\/(?:v\/)?(\d+))?/ url = "//player.twitch.tv/?#{if m[2] then "video=v#{m[2]}" else "channel=#{m[1]}"}&autoplay=false&parent=#{location.hostname}" From ca019d199781ecde8792e4ce97b2a4959ba3f7ba Mon Sep 17 00:00:00 2001 From: WastedMeerkat Date: Thu, 21 Oct 2021 00:43:38 -0500 Subject: [PATCH 4/4] Accomodated alternate clip URL scheme https://twitch.tv//clips/ clip links now work --- src/Linkification/Embedding.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Linkification/Embedding.coffee b/src/Linkification/Embedding.coffee index f220c73d2..2187c06d1 100644 --- a/src/Linkification/Embedding.coffee +++ b/src/Linkification/Embedding.coffee @@ -424,7 +424,7 @@ Embedding = key: 'TwitchTV' regExp: /^\w+:\/\/(?:www\.|secure\.|clips\.|m\.)?twitch\.tv\/(\w[^#\&\?]*)/ el: (a) -> - m = a.dataset.href.match /^\w+:\/\/(?:(clips\.)|\w+\.)?twitch\.tv\/(clip\/)?(\w[^#\&\?]*)/; + m = a.dataset.href.match /^\w+:\/\/(?:(clips\.)|\w+\.)?twitch\.tv\/(?:\w+\/)?(clip\/)?(\w[^#\&\?]*)/; if m[1] or m[2] url = "//clips.twitch.tv/embed?clip=#{m[3]}&parent=#{location.hostname}" else