Merge pull request #1109 from AStove/TikTok

Add TikTok plugin
codeql
Lorenz Hübschle-Schneider 5 years ago committed by GitHub
commit c7a5a65ed7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 36
      js/plugins.js
  2. 10
      test/unit/plugins.js

@ -553,8 +553,42 @@ plugins.factory('userPlugins', function() {
}
});
/*
* TikTok embedded player
* Very similar to twitter
*/
var tikTokPlugin = new UrlPlugin('TikTok', function(url) {
var regex = /^https?:\/\/(www\.)?tiktok\.com\/@(.+)\/video\/(.+)/i,
match = url.match(regex);
if (match) {
return function() {
var element = this.getElement();
fetch("https://www.tiktok.com/oembed?url=" + url)
.then(function(response) {
return response.json();
})
.then(function(data) {
// separate the HTML into content and script tag
var scriptIndex = data.html.indexOf("<script ");
var content = data.html.substr(0, scriptIndex);
element.innerHTML = content;
// The script tag needs to be generated manually or the browser won't load it
var scriptElem = document.createElement('script');
// Hardcoding the URL here, I don't suppose it's going to change anytime soon
scriptElem.src = "https://www.tiktok.com/embed.js";
element.appendChild(scriptElem);
});
};
}
});
return {
plugins: [youtubePlugin, dailymotionPlugin, allocinePlugin, imagePlugin, videoPlugin, audioPlugin, spotifyPlugin, cloudmusicPlugin, googlemapPlugin, asciinemaPlugin, yrPlugin, gistPlugin, pastebinPlugin, giphyPlugin, tweetPlugin, streamablePlugin]
plugins: [youtubePlugin, dailymotionPlugin, allocinePlugin, imagePlugin, videoPlugin, audioPlugin, spotifyPlugin, cloudmusicPlugin, googlemapPlugin, asciinemaPlugin, yrPlugin, gistPlugin, pastebinPlugin, giphyPlugin, tweetPlugin, streamablePlugin, tikTokPlugin]
};

@ -169,5 +169,15 @@ describe('filter', function() {
plugins);
}));
it('should recognize tiktoks', inject(function(plugins) {
expectTheseMessagesToContain([
'https://www.tiktok.com/@scout2015/video/6718335390845095173',
'https://www.tiktok.com/@lewiscatpaldi/video/6800461190058298629',
'https://www.tiktok.com/@bhattrai_fam5_kavita/video/6811222914768047365',
],
'TikTok',
plugins);
}));
});
});

Loading…
Cancel
Save