Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name IMDB Copy Title
- // @namespace YP
- // @version 2021.0122.1911
- // @description Copy Title, year and ID to the clipboard
- // @author Yunga Palatino <yunga.palatino@gmail.com>
- //
- // @grant GM_setClipboard
- // @run-at idle
- // @inject-into auto
- // @noframes
- //
- // @match https://*.imdb.com/title/tt*
- // ==/UserScript==
- function yp_imdb_copy_title() {
- "use strict";
- const myName = `imdbCopyTitle`;
- let imdbID = /\/tt(\d+)\//.exec( document.URL );
- let titleElement = document.querySelector( '.title_wrapper > h1:nth-child(1)' );
- if ( titleElement && imdbID ) {
- let newTitle = ( titleElement.innerText + " (tt" + imdbID[1] + ")" )
- .replace(/:/g, ' - ')
- .replace(/\s+/g, ' ')
- .replace(/^\s+/g, '')
- .replace(/\s+$/g, '');
- titleElement.innerText = newTitle;
- console.log( `${myName} - Suggested title: ${newTitle}` );
- GM_setClipboard( newTitle );
- } else {
- console.log( `${myName} - Something went wrong.` );
- console.log( `${myName} - Title[${titleElement}] ID[${imdbID}]`);
- }
- }
- yp_imdb_copy_title();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement