From 2e7e71be88850921185e51ab97ecb0bfb383b7e5 Mon Sep 17 00:00:00 2001 From: Ivan Paramonau Date: Fri, 5 Dec 2025 12:44:54 -0500 Subject: [PATCH 1/2] [Domains] Fix Bunny CDN autoplay issues via Twitter Player domain flags --- lib/plugins/validators/sync/06_autoplay.js | 58 +++++++++++++++------- 1 file changed, 39 insertions(+), 19 deletions(-) diff --git a/lib/plugins/validators/sync/06_autoplay.js b/lib/plugins/validators/sync/06_autoplay.js index 2c8880c9d..61ac91f41 100644 --- a/lib/plugins/validators/sync/06_autoplay.js +++ b/lib/plugins/validators/sync/06_autoplay.js @@ -27,7 +27,17 @@ export default { // don't need this field any longer delete link.autoplay; - if (link.href.indexOf(play) > -1 || link.rel.indexOf(CONFIG.R.autoplay) == -1) { + /** + * Three cases: + * 1) Link does not autoplay by default. We need to add an autoplay with autoplay=1. + * 2) Link autoplays: + * - with autoplay=1 in src, maybe with no autoplay in rels + * - or without autoplay=1 in src, but autoplay in rels + * We need to add a non-autoplaying variant with autoplay=0 + */ + if ((link.href.indexOf(play) === -1 && link.rel.indexOf(CONFIG.R.autoplay) === -1) + || link.href.indexOf(play) > -1 + || link.rel.indexOf(CONFIG.R.autoplay) > -1) { var stop = play.replace(/\=(\w+)/, function (p1, p2) { var antonyms = { @@ -39,37 +49,47 @@ export default { 'off': 'on' }; return '=' + antonyms[p2]; - }); + }); - var rels = [...link.rel]; + const rel = link.rel; + const RELS = [...rel]; + RELS.splice(link.rel.indexOf(CONFIG.R.autoplay), 1); + delete link.rel; + + const RELS_WITH_AUTOPLAY = [...RELS, CONFIG.R.autoplay]; var new_link = Object.assign({}, link); - new_link.rel = rels; // deep copy + if (link.href.indexOf(play) > -1 ) { - if (link.href.indexOf(play) > -1 ) { - // original link is autoplay - if (link.rel.indexOf(CONFIG.R.autoplay) == -1 ) { - link.rel.push(CONFIG.R.autoplay); - } - + // Original link is autoplay + link.rel = RELS_WITH_AUTOPLAY; + + // Add a link without autoplay new_link.href = new_link.href.replace(play, stop); - if (new_link.rel.indexOf(CONFIG.R.autoplay) > -1 ) { - new_link.rel.splice(new_link.rel.indexOf(CONFIG.R.autoplay), 1); - } + new_link.rel = RELS; - } else if (link.rel.indexOf(CONFIG.R.autoplay) == -1) { + } else if (/* link.href.indexOf(play) === -1 && */ rel.indexOf(CONFIG.R.autoplay) > -1 ) { - // original link isnt autoplay, leave it alone - // autoplay=false may autoplay. Many publishers react to any `autoplay` value + link.rel = RELS_WITH_AUTOPLAY; + // link.href.indexOf(play) === -1, no need to double-check + // Add a link without autoplay + new_link.href += (new_link.href.indexOf('?') > -1 ? '&' : '?') + stop; + new_link.rel = RELS; + + } else if (rel.indexOf(CONFIG.R.autoplay) === -1) { + + // Original link isnt autoplay, leave it as is + link.rel = RELS; + + // Add a link with autoplay if (link.href.indexOf(stop) > -1) { new_link.href = new_link.href.replace(stop, play); } else { - new_link.href += (new_link.href.indexOf('?') > -1 ? '&' : '?') + play; + new_link.href += (new_link.href.indexOf('?') > -1 ? '&' : '?') + play; } - new_link.rel.push(CONFIG.R.autoplay); - + new_link.rel = RELS_WITH_AUTOPLAY; } return { From 275cc9a9d707a9b2d99ead964d63f230381ab9ad Mon Sep 17 00:00:00 2001 From: Ivan Paramonau Date: Fri, 5 Dec 2025 15:17:16 -0500 Subject: [PATCH 2/2] simplify code --- lib/plugins/validators/sync/06_autoplay.js | 118 +++++++++------------ 1 file changed, 48 insertions(+), 70 deletions(-) diff --git a/lib/plugins/validators/sync/06_autoplay.js b/lib/plugins/validators/sync/06_autoplay.js index 61ac91f41..1652b453f 100644 --- a/lib/plugins/validators/sync/06_autoplay.js +++ b/lib/plugins/validators/sync/06_autoplay.js @@ -23,80 +23,58 @@ export default { // create autoplay variant of the player if requested via link.autoplay attribute if (link.href && link.rel.indexOf(CONFIG.R.player) > -1 && link.autoplay && typeof link.autoplay === "string" && link.autoplay.indexOf('=') > -1) { // it should always be a query-string - var play = link.autoplay; - // don't need this field any longer + const play_querystring = link.autoplay; // e.g. 'autoplay=1' delete link.autoplay; - - /** - * Three cases: - * 1) Link does not autoplay by default. We need to add an autoplay with autoplay=1. - * 2) Link autoplays: - * - with autoplay=1 in src, maybe with no autoplay in rels - * - or without autoplay=1 in src, but autoplay in rels - * We need to add a non-autoplaying variant with autoplay=0 - */ - if ((link.href.indexOf(play) === -1 && link.rel.indexOf(CONFIG.R.autoplay) === -1) - || link.href.indexOf(play) > -1 - || link.rel.indexOf(CONFIG.R.autoplay) > -1) { - - var stop = play.replace(/\=(\w+)/, function (p1, p2) { - var antonyms = { - '1': '0', - '0': '1', - 'true': 'false', - 'false': 'true', - 'on': 'off', - 'off': 'on' - }; - return '=' + antonyms[p2]; - }); - - const rel = link.rel; - const RELS = [...rel]; - RELS.splice(link.rel.indexOf(CONFIG.R.autoplay), 1); - delete link.rel; - - const RELS_WITH_AUTOPLAY = [...RELS, CONFIG.R.autoplay]; - var new_link = Object.assign({}, link); - - if (link.href.indexOf(play) > -1 ) { - - // Original link is autoplay - link.rel = RELS_WITH_AUTOPLAY; - - // Add a link without autoplay - new_link.href = new_link.href.replace(play, stop); - new_link.rel = RELS; - - } else if (/* link.href.indexOf(play) === -1 && */ rel.indexOf(CONFIG.R.autoplay) > -1 ) { - - link.rel = RELS_WITH_AUTOPLAY; - - // link.href.indexOf(play) === -1, no need to double-check - // Add a link without autoplay - new_link.href += (new_link.href.indexOf('?') > -1 ? '&' : '?') + stop; - new_link.rel = RELS; - - } else if (rel.indexOf(CONFIG.R.autoplay) === -1) { - - // Original link isnt autoplay, leave it as is - link.rel = RELS; - - // Add a link with autoplay - if (link.href.indexOf(stop) > -1) { - new_link.href = new_link.href.replace(stop, play); - } else { - new_link.href += (new_link.href.indexOf('?') > -1 ? '&' : '?') + play; - } - - new_link.rel = RELS_WITH_AUTOPLAY; - } - return { - addLink: new_link + const stop_querystring = play_querystring.replace(/\=(\w+)/, function (p1, p2) { + const antonyms = { + '1': '0', + '0': '1', + 'true': 'false', + 'false': 'true', + 'on': 'off', + 'off': 'on' }; + return '=' + antonyms[p2]; + }); + + // Fix original link first, if needed + if (link.href.indexOf(play_querystring) > -1 && link.rel.indexOf(CONFIG.R.autoplay) === -1) { + link.rel.push(CONFIG.R.autoplay); } - + + if (link.href.indexOf(stop_querystring) > -1 && link.rel.indexOf(CONFIG.R.autoplay) > -1) { + link.rel.splice(link.rel.indexOf(CONFIG.R.autoplay), 1); + } + + var other = Object.assign({}, link); + other.rel = [...link.rel]; + + if (link.rel.indexOf(CONFIG.R.autoplay) === -1) { + + // Add a link with autoplay + if (link.href.indexOf(stop_querystring) > -1) { + other.href = other.href.replace(stop_querystring, play_querystring); + } else { + other.href += (other.href.indexOf('?') > -1 ? '&' : '?') + play_querystring; + } + other.rel.push(CONFIG.R.autoplay); + + } else { + + // Add a link without autoplay + if (link.href.indexOf(play_querystring) > -1) { + other.href = other.href.replace(play_querystring, stop_querystring); + } else { + other.href += (other.href.indexOf('?') > -1 ? '&' : '?') + stop_querystring; + } + other.rel.splice(other.rel.indexOf(CONFIG.R.autoplay), 1); + } + + return { + addLink: other + }; + } else if (link.autoplay) { delete link.autoplay; // if not a string - just ignore it }