You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

91 lines
2.5 KiB

  1. /**
  2. * Append a toolbar button
  3. */
  4. if (window.toolbar !== undefined) {
  5. toolbar[toolbar.length] = {
  6. "type": "pluginvshare",
  7. "title": LANG['plugins']['vshare']['button'],
  8. "icon": "../../plugins/vshare/button.png",
  9. "key": ""
  10. };
  11. }
  12. /**
  13. * Try to determine the video service, extract the ID and insert
  14. * the correct syntax
  15. */
  16. function tb_pluginvshare(btn, props, edid) {
  17. PluginVShare.edid = edid;
  18. PluginVShare.buildSyntax();
  19. }
  20. const PluginVShare = {
  21. edid: null,
  22. /**
  23. * Ask for URL, extract data and create syntax
  24. */
  25. buildSyntax: function () {
  26. const text = prompt(LANG['plugins']['vshare']['prompt']);
  27. if (!text) return;
  28. for (const [site, rex] of Object.entries(JSINFO.plugins.vshare)) {
  29. const RE = new RegExp(rex, 'i');
  30. const match = text.match(RE);
  31. if (match) {
  32. const urlparam = '';
  33. const videoid = match[1];
  34. PluginVShare.insert(site, videoid, urlparam);
  35. return;
  36. }
  37. }
  38. alert(LANG['plugins']['vshare']['notfound']);
  39. },
  40. /**
  41. * Insert the syntax in the editor
  42. *
  43. * @param {string} key
  44. * @param {string} videoid
  45. * @param {string} urlparam
  46. */
  47. insert: function (key, videoid, urlparam) {
  48. const code = '{{' + key + '>' + videoid + '?' + urlparam + '}}';
  49. insertAtCarret(PluginVShare.edid, code);
  50. },
  51. /**
  52. * Allow loading videos on click
  53. */
  54. attachGDPRHandler: function () {
  55. const $videos = jQuery('div.vshare');
  56. // add click handler
  57. $videos.on('click', function () {
  58. // create an iframe and copy over the attributes
  59. const iframe = document.createElement('iframe');
  60. let attr;
  61. let attributes = Array.prototype.slice.call(this.attributes);
  62. while(attr = attributes.pop()) {
  63. iframe.setAttribute(attr.nodeName, attr.nodeValue);
  64. }
  65. // replace the div with the iframe
  66. this.replaceWith(iframe);
  67. });
  68. // add info text
  69. $videos.each(function (){
  70. const $self = jQuery(this);
  71. const info = document.createElement('p');
  72. info.innerText = LANG.plugins.vshare.click.replace('%s', $self.data('domain'));
  73. $self.append(info);
  74. });
  75. }
  76. };
  77. jQuery(function () {
  78. PluginVShare.attachGDPRHandler();
  79. });