Skip to content

Commit e24a2eb

Browse files
committed
Oembed change twitter domain to x, added silent parameter to hide warnings if url is not in the oembed providers list
1 parent c66a4e9 commit e24a2eb

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

public/js/libs/oembed.js

+13-10
Original file line numberDiff line numberDiff line change
@@ -56,27 +56,27 @@ const oEmbedProviders = [
5656
url: "https://www.scribd.com/services/oembed"
5757
},
5858
{
59-
regex: /https?:\/\/(www\.)?twitter\.com\/\w{1,15}\/status(es)?\/.*/,
59+
regex: /https?:\/\/(www\.)?x\.com\/\w{1,15}\/status(es)?\/.*/,
6060
url: "https://publish.twitter.com/oembed"
6161
},
6262
{
63-
regex: /https?:\/\/(www\.)?twitter\.com\/\w{1,15}$/,
63+
regex: /https?:\/\/(www\.)?x\.com\/\w{1,15}$/,
6464
url: "https://publish.twitter.com/oembed"
6565
},
6666
{
67-
regex: /https?:\/\/(www\.)?twitter\.com\/\w{1,15}\/likes$/,
67+
regex: /https?:\/\/(www\.)?x\.com\/\w{1,15}\/likes$/,
6868
url: "https://publish.twitter.com/oembed"
6969
},
7070
{
71-
regex: /https?:\/\/(www\.)?twitter\.com\/\w{1,15}\/lists\/.*/,
71+
regex: /https?:\/\/(www\.)?x\.com\/\w{1,15}\/lists\/.*/,
7272
url: "https://publish.twitter.com/oembed"
7373
},
7474
{
75-
regex: /https?:\/\/(www\.)?twitter\.com\/\w{1,15}\/timelines\/.*/,
75+
regex: /https?:\/\/(www\.)?x\.com\/\w{1,15}\/timelines\/.*/,
7676
url: "https://publish.twitter.com/oembed"
7777
},
7878
{
79-
regex: /https?:\/\/(www\.)?twitter\.com\/i\/moments\/.*/,
79+
regex: /https?:\/\/(www\.)?x\.com\/i\/moments\/.*/,
8080
url: "https://publish.twitter.com/oembed"
8181
},
8282
{
@@ -260,12 +260,13 @@ const urlTransforms = [
260260
}
261261
];
262262

263-
async function getOembed(url, maxwidth = 800, maxheight = 600) {
263+
async function getOembed(url, maxwidth = 800, maxheight = 600, silent = false) {
264264
let oembedUrl;
265265

266266
for (const service of oEmbedProviders) {
267267
if (service.regex.exec(url)) {
268-
oembedUrl = service.url + `?url=${url}&maxwidth=${maxwidth}&maxheight=${maxheight}&format=json`;
268+
let eurl = encodeURIComponent(url);
269+
oembedUrl = service.url + `?url=${eurl}&maxwidth=${maxwidth}&maxheight=${maxheight}&format=json`;
269270
}
270271
}
271272

@@ -289,8 +290,10 @@ async function getOembed(url, maxwidth = 800, maxheight = 600) {
289290
return {html: transform};
290291
}
291292

292-
let message = 'Embed error: URL did not match any provider.';
293-
displayToast("bg-danger", "Error", message);
293+
if (!silent) {
294+
let message = 'Embed error: URL did not match any provider.';
295+
displayToast("bg-danger", "Error", message);
296+
}
294297

295298
return;
296299
}

0 commit comments

Comments
 (0)