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