From a8ff945fbc71dc229023aed7405b06c80a64cf77 Mon Sep 17 00:00:00 2001 From: leprechaun Date: Sat, 31 Jul 2021 10:32:10 -0300 Subject: [PATCH 1/9] * embedded Rumble video support added. --- src/consts/regexes.const.ts | 3 ++- src/markdown-2-html.spec.ts | 43 +++++++++++++++++++++++++++++++----- src/methods/a.method.ts | 30 +++++++++++++++++++------ src/methods/iframe.method.ts | 22 +++++++++++++----- 4 files changed, 79 insertions(+), 19 deletions(-) diff --git a/src/consts/regexes.const.ts b/src/consts/regexes.const.ts index 3ab48db..cdad99d 100644 --- a/src/consts/regexes.const.ts +++ b/src/consts/regexes.const.ts @@ -19,4 +19,5 @@ export const ODYSEE_REGEX = /^(https?:)?\/\/odysee.com\/\$\/embed\/.*/i export const ARCH_REGEX = /^(https?:)?\/\/archive.org\/embed\/.*/i export const SPEAK_REGEX = /(?:https?:\/\/(?:3speak.([a-z]+)\/watch\?v=)|(?:3speak.([a-z]+)\/embed\?v=))([A-Za-z0-9\_\-\.\/]+)(&.*)?/i export const TWITTER_REGEX = /(?:https?:\/\/(?:(?:twitter\.com\/(.*?)\/status\/(.*))))/gi -export const SPOTIFY_REGEX = /^https:\/\/open\.spotify\.com\/playlist\/(.*)?$/gi \ No newline at end of file +export const SPOTIFY_REGEX = /^https:\/\/open\.spotify\.com\/playlist\/(.*)?$/gi +export const RUMBLE_REGEX = /^https:\/\/rumble.com\/embed\/(?[a-zA-Z0-9-]+)\/\?pub=4/ \ No newline at end of file diff --git a/src/markdown-2-html.spec.ts b/src/markdown-2-html.spec.ts index a48a167..f9ba7ac 100644 --- a/src/markdown-2-html.spec.ts +++ b/src/markdown-2-html.spec.ts @@ -677,7 +677,7 @@ describe('Markdown2Html', () => { const expected = '

for history refer to this fine post /@offgridlife/proofofbrain-golden-rule-do-to-others-what-you-want-them-to-do-to-you and while you are in the community

' expect(markdown2Html(input)).toBe(expected) - }) + }) it('47 - Should handle Bitchute links', () => { const input = { @@ -687,9 +687,9 @@ describe('Markdown2Html', () => { body: 'https://www.bitchute.com/video/DJJvTZQxMaNK/' } const expected = '

' - expect(markdown2Html(input)).toBe(expected); + expect(markdown2Html(input)).toBe(expected) }) - + it('49 - Should handle Bitchute iframes', () => { const input = { author: 'foo349', @@ -698,9 +698,10 @@ describe('Markdown2Html', () => { body: '' } const expected = '' - expect(markdown2Html(input)).toBe(expected); + expect(markdown2Html(input)).toBe(expected) }) - + + }) describe('Sanitization', () => { @@ -858,4 +859,36 @@ describe('Markdown2Html', () => { expect(markdown2Html(input, false, true)).toBe(SNAPSHOT_JSON.markdown_2_html_webp_support_should_render_images_in_webp_format) }) }) + + describe("Rumble support", () => { + + it('Rumble iframes', () => { + let expected = '' + let input = { + author: 'foo350x', + permlink: 'bar350x', + last_update: '2021-05-10T09:15:50', + body: '' + } + expect(markdown2Html(input)).toBe(expected) + }) + + + it('Rumble embed URL', () => { + const expected = "

" + let input = { + author: 'foo350y', + permlink: 'bar350y', + last_update: '2021-05-10T09:16:50', + body: 'https://rumble.com/embed/vhwsp4/?pub=4' + } + expect(markdown2Html(input)).toBe(expected) + }) + + // The following canot be done: Convert URLs to the video page like this one + // (https://rumble.com/vkhkzl-helping-my-girls-to-cool-down-in-the-heat.html) + // to its corresponding embedded URL (https://rumble.com/embed/vhveub/?pub=4). + // The relationship seems to be governed by a table. + + }) }) diff --git a/src/methods/a.method.ts b/src/methods/a.method.ts index e291a41..24bb112 100644 --- a/src/methods/a.method.ts +++ b/src/methods/a.method.ts @@ -14,6 +14,7 @@ import { TWITTER_REGEX, VIMEO_REGEX, WHITE_LIST, + RUMBLE_REGEX, YOUTUBE_REGEX, SPOTIFY_REGEX, DOMParser @@ -225,6 +226,21 @@ export function a(el: HTMLElement, forApp: boolean, webp: boolean): void { return } + const RBmatch = href.match(RUMBLE_REGEX) + if (RBmatch && el.textContent.trim() === href) { + const vid = RBmatch.groups.id + const embedSrc = `https://www.rumble.com/embed/${vid}/?pub=4` + el.setAttribute('class', 'markdown-video-link') + el.removeAttribute('href') + + el.textContent = '' + el.setAttribute('data-embed-src', embedSrc) + const play = el.ownerDocument.createElement('span') + play.setAttribute('class', 'markdown-video-play') + el.appendChild(play) + return + } + const BCmatch = href.match(BITCHUTE_REGEX) if (BCmatch && el.textContent.trim() === href) { @@ -241,11 +257,11 @@ export function a(el: HTMLElement, forApp: boolean, webp: boolean): void { const play = el.ownerDocument.createElement('span') play.setAttribute('class', 'markdown-video-play') el.appendChild(play) - return; + return } - + // If a youtube video let match = href.match(YOUTUBE_REGEX) if (match && el.textContent.trim() === href) { @@ -332,7 +348,7 @@ export function a(el: HTMLElement, forApp: boolean, webp: boolean): void { if (match && el.textContent.trim() === href) { const e = SPOTIFY_REGEX.exec(href) if (e[1]) { - + el.setAttribute('class', 'markdown-audio-link markdown-audio-link-spotify') el.removeAttribute('href') @@ -347,7 +363,7 @@ export function a(el: HTMLElement, forApp: boolean, webp: boolean): void { ifr.setAttribute('sandbox', 'allow-scripts allow-same-origin allow-popups') el.appendChild(ifr) - return + return } } @@ -367,13 +383,13 @@ export function a(el: HTMLElement, forApp: boolean, webp: boolean): void { const thumbnail = proxifyImageSrc(imgEls[0].getAttribute('src').replace(/\s+/g, ''), 0, 0, webp ? 'webp' : 'match') const videoHref = `https://emb.d.tube/#!/${e[2]}/${e[3]}` - // el.setAttribute('data-video-href', videoHref); + // el.setAttribute('data-video-href', videoHref) el.setAttribute('data-embed-src', videoHref) const thumbImg = el.ownerDocument.createElement('img') thumbImg.setAttribute('class', 'no-replace video-thumbnail') thumbImg.setAttribute('itemprop', 'thumbnailUrl') - + thumbImg.setAttribute('src', thumbnail) const play = el.ownerDocument.createElement('span') @@ -399,7 +415,7 @@ export function a(el: HTMLElement, forApp: boolean, webp: boolean): void { const videoHref = `https://emb.d.tube/#!/${e[2]}/${e[3]}` - // el.setAttribute('data-video-href', videoHref); + // el.setAttribute('data-video-href', videoHref) el.setAttribute('data-embed-src', videoHref) const play = el.ownerDocument.createElement('span') play.setAttribute('class', 'markdown-video-play') diff --git a/src/methods/iframe.method.ts b/src/methods/iframe.method.ts index 5660bb3..101eabe 100644 --- a/src/methods/iframe.method.ts +++ b/src/methods/iframe.method.ts @@ -1,4 +1,4 @@ -import { ARCH_REGEX, DAPPLR_REGEX, LBRY_REGEX, TRUVVL_REGEX, ODYSEE_REGEX, BITCHUTE_REGEX } from '../consts' +import { ARCH_REGEX, DAPPLR_REGEX, LBRY_REGEX, TRUVVL_REGEX, ODYSEE_REGEX, BITCHUTE_REGEX, RUMBLE_REGEX } from '../consts' export function iframe(el: HTMLElement): void { const src = el.getAttribute('src') @@ -7,6 +7,12 @@ export function iframe(el: HTMLElement): void { return } + try { + + if (src.match(BITCHUTE_REGEX)) { + return + } + // Youtube if (src.match(/^(https?:)?\/\/www.youtube.com\/embed\/.*/i)) { // strip query string (yt: autoplay=1,controls=0,showinfo=0, etc) @@ -15,10 +21,6 @@ export function iframe(el: HTMLElement): void { return } - if (src.match(BITCHUTE_REGEX)) { - return - } - // Vimeo const m = src.match(/https:\/\/player\.vimeo\.com\/video\/([0-9]+)/) if (m && m.length === 2) { @@ -86,7 +88,7 @@ export function iframe(el: HTMLElement): void { el.setAttribute('allowfullscreen', 'true') return } - + // Truvvl if (src.match(TRUVVL_REGEX)) { el.setAttribute('src', src) @@ -104,6 +106,11 @@ export function iframe(el: HTMLElement): void { return } + if (src.match(RUMBLE_REGEX)) { + el.setAttribute('frameborder', '0') + return + } + // ODYSEE if (src.match(ODYSEE_REGEX)) { el.setAttribute('src', src) @@ -116,6 +123,9 @@ export function iframe(el: HTMLElement): void { el.setAttribute('src', src) return } + } catch (e) { + console.log(e) + } const replaceNode = el.ownerDocument.createElement('div') replaceNode.setAttribute('class', 'unsupported-iframe') From e7b55b8e6b3f4d607e4597da67e299da969c1bf8 Mon Sep 17 00:00:00 2001 From: leprechaun Date: Sat, 31 Jul 2021 22:04:20 -0300 Subject: [PATCH 2/9] * support for brighteon videos added --- src/consts/regexes.const.ts | 3 ++- src/markdown-2-html.spec.ts | 39 ++++++++++++++++++++++++++++++++++++ src/methods/a.method.ts | 22 ++++++++++++++++++++ src/methods/iframe.method.ts | 7 ++++++- 4 files changed, 69 insertions(+), 2 deletions(-) diff --git a/src/consts/regexes.const.ts b/src/consts/regexes.const.ts index cdad99d..18c871a 100644 --- a/src/consts/regexes.const.ts +++ b/src/consts/regexes.const.ts @@ -20,4 +20,5 @@ export const ARCH_REGEX = /^(https?:)?\/\/archive.org\/embed\/.*/i export const SPEAK_REGEX = /(?:https?:\/\/(?:3speak.([a-z]+)\/watch\?v=)|(?:3speak.([a-z]+)\/embed\?v=))([A-Za-z0-9\_\-\.\/]+)(&.*)?/i export const TWITTER_REGEX = /(?:https?:\/\/(?:(?:twitter\.com\/(.*?)\/status\/(.*))))/gi export const SPOTIFY_REGEX = /^https:\/\/open\.spotify\.com\/playlist\/(.*)?$/gi -export const RUMBLE_REGEX = /^https:\/\/rumble.com\/embed\/(?[a-zA-Z0-9-]+)\/\?pub=4/ \ No newline at end of file +export const RUMBLE_REGEX = /^https:\/\/rumble\.com\/embed\/(?[a-zA-Z0-9-]+)\/\?pub=4/ +export const BRIGHTEON_REGEX = /^https?:\/\/(www\.)?brighteon\.com\/(?:embed\/)?(?[0-9a-f-]+)/i \ No newline at end of file diff --git a/src/markdown-2-html.spec.ts b/src/markdown-2-html.spec.ts index f9ba7ac..e337548 100644 --- a/src/markdown-2-html.spec.ts +++ b/src/markdown-2-html.spec.ts @@ -890,5 +890,44 @@ describe('Markdown2Html', () => { // to its corresponding embedded URL (https://rumble.com/embed/vhveub/?pub=4). // The relationship seems to be governed by a table. + }) + describe("Brightreon support", () => { + + it('Brightreon iframes', () => { + let expected = '' + let input = { + author: 'foo351x', + permlink: 'bar351x', + last_update: '2021-05-10T09:15:50', + body: "" + } + expect(markdown2Html(input)).toBe(expected) + }) + + + it('Brightreon embed URL', () => { + const expected = "

" + let input = { + author: 'foo351y', + permlink: 'bar351y', + last_update: '2021-05-10T09:16:50', + body: 'https://www.brighteon.com/embed/5821540656001' + } + expect(markdown2Html(input)).toBe(expected) + }) + + it('Brightreon page URL', () => { + const expected = "

" + let input = { + author: 'foo351z', + permlink: 'bar351z', + last_update: '2021-05-10T09:16:50', + body: 'https://www.brighteon.com/5821540656001' + } + expect(markdown2Html(input)).toBe(expected) + }) + + + }) }) diff --git a/src/methods/a.method.ts b/src/methods/a.method.ts index 24bb112..5f5a032 100644 --- a/src/methods/a.method.ts +++ b/src/methods/a.method.ts @@ -15,6 +15,7 @@ import { VIMEO_REGEX, WHITE_LIST, RUMBLE_REGEX, + BRIGHTEON_REGEX, YOUTUBE_REGEX, SPOTIFY_REGEX, DOMParser @@ -226,6 +227,27 @@ export function a(el: HTMLElement, forApp: boolean, webp: boolean): void { return } + const BNmatch = href.match(BRIGHTEON_REGEX) + if (BNmatch && el.textContent.trim() === href) { + try { + const vid = BNmatch.groups.id + const embedSrc = `https://www.brighteon.com/embed/${vid}` + el.setAttribute('class', 'markdown-video-link') + el.removeAttribute('href') + + el.textContent = '' + el.setAttribute('data-embed-src', embedSrc) + const play = el.ownerDocument.createElement('span') + play.setAttribute('class', 'markdown-video-play') + el.appendChild(play) + return + } catch (e) { + console.log(e) + console.log({BNmatch}) + } + } + + const RBmatch = href.match(RUMBLE_REGEX) if (RBmatch && el.textContent.trim() === href) { const vid = RBmatch.groups.id diff --git a/src/methods/iframe.method.ts b/src/methods/iframe.method.ts index 101eabe..9397b16 100644 --- a/src/methods/iframe.method.ts +++ b/src/methods/iframe.method.ts @@ -1,4 +1,4 @@ -import { ARCH_REGEX, DAPPLR_REGEX, LBRY_REGEX, TRUVVL_REGEX, ODYSEE_REGEX, BITCHUTE_REGEX, RUMBLE_REGEX } from '../consts' +import { ARCH_REGEX, DAPPLR_REGEX, LBRY_REGEX, TRUVVL_REGEX, ODYSEE_REGEX, BITCHUTE_REGEX, RUMBLE_REGEX, BRIGHTEON_REGEX } from '../consts' export function iframe(el: HTMLElement): void { const src = el.getAttribute('src') @@ -110,6 +110,11 @@ export function iframe(el: HTMLElement): void { el.setAttribute('frameborder', '0') return } + + if (src.match(BRIGHTEON_REGEX)) { + el.setAttribute('frameborder', '0') + return + } // ODYSEE if (src.match(ODYSEE_REGEX)) { From 2bc5cc68da698b6b646879c7dfbd0bc526ca46c0 Mon Sep 17 00:00:00 2001 From: leprechaun Date: Tue, 3 Aug 2021 16:22:25 -0300 Subject: [PATCH 3/9] * added support for embedding codes from InfoWars --- src/consts/regexes.const.ts | 2 ++ src/markdown-2-html.spec.ts | 41 ++++++++++++++++++++++++++++++++++ src/methods/a.method.ts | 35 +++++++++++++++++++++++++++++ src/methods/iframe.method.ts | 12 +++++++++- src/methods/traverse.method.ts | 31 ++++++++++++++++++++++++- 5 files changed, 119 insertions(+), 2 deletions(-) diff --git a/src/consts/regexes.const.ts b/src/consts/regexes.const.ts index 18c871a..3752c88 100644 --- a/src/consts/regexes.const.ts +++ b/src/consts/regexes.const.ts @@ -9,6 +9,8 @@ export const COMMUNITY_REGEX = /^https?:\/\/(.*)\/c\/(hive-\d+)(.*)/i export const YOUTUBE_REGEX = /(?:https?:\/\/)?(?:www\.)?(?:youtube\.com\/watch\?v=|youtu\.be\/)([^& \n<]+)(?:[^ \n<]+)?/g export const VIMEO_REGEX = /(https?:\/\/)?(www\.)?(?:vimeo)\.com.*(?:videos|video|channels|)\/([\d]+)/i export const BITCHUTE_REGEX = /^(?:https?:\/\/)?(?:www\.)?bitchute.com\/(?:video|embed)\/([a-z0-9]+)/i +export const INFOWARS_REGEX = /https:\/\/(?infowars\.com|freeworldnews\.tv)\/watch\?id=(?