-
Notifications
You must be signed in to change notification settings - Fork 0
/
imdb-filename-generator.user.js
82 lines (63 loc) · 2.45 KB
/
imdb-filename-generator.user.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
// ==UserScript==
// @name IMDB Filename Generator
// @description Generate a filename of the shown movie for use in Emby or Jellyfin
// @version 0.1.2
// @author @bennyborn
// @namespace https://github.com/bennyborn
// @match https://www.imdb.com/title/tt*
// @run-at document-end
// @grant GM_addStyle
// @updateURL https://raw.githubusercontent.com/bennyborn/tampermonkey-scripts/master/imdb-filename-generator.user.js
// @downloadURL https://raw.githubusercontent.com/bennyborn/tampermonkey-scripts/master/imdb-filename-generator.user.js
// ==/UserScript==
(function() {
'use strict';
GM_addStyle(`
button.copyButton {
position: fixed;
z-index: 10;
left: 1em;
bottom: 1em;
display: inline-block;
padding: 1.25em 2em;
background: #f5c518;
cursor: pointer;
border: 0;
border-radius: 5px;
font-family: var(--ipt-font-family);
font-size: var(--ipt-font-root-size);
color: rgb(0, 0, 0);
}
button.copyButton:hover {
background: #000;
color: #fff;
}
`);
const button = document.createElement('BUTTON');
button.className = 'copyButton';
button.dataset.textDefault = 'Copy filename';
button.dataset.textCopied = 'copied!';
button.innerText = button.dataset.textDefault;
button.style = '';
document.body.appendChild(button);
button.addEventListener('click', function(e){
let title = document.querySelector('h1[data-testid="hero-title-block__title"]').innerText;
title += ' (' + document.querySelector('[data-testid="hero-title-block__metadata"] span').textContent + ')';
const id = document.location.href.match(/imdb\.com\/title\/([t0-9]+)/)[1];
copyStringToClipboard(`${title} [imdbid=${id}]`);
this.innerText = button.dataset.textCopied;
setTimeout(function(){
button.innerText = button.dataset.textDefault;
},3000);
});
const copyStringToClipboard = (str)=>{
const el = document.createElement('textarea');
el.value = str;
el.setAttribute('readonly', '');
el.style = {position: 'absolute', left: '-9999px'};
document.body.appendChild(el);
el.select();
document.execCommand('copy');
document.body.removeChild(el);
}
})();