Advertisement
Yunga

IMDB - Copy Title and ID.user.js

Apr 24th, 2021
861
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name              IMDB Copy Title
  3. // @namespace         YP
  4. // @version           2021.0122.1911
  5. // @description       Copy Title, year and ID to the clipboard
  6. // @author            Yunga Palatino <yunga.palatino@gmail.com>
  7. //
  8. // @grant             GM_setClipboard
  9. // @run-at            idle
  10. // @inject-into       auto
  11. // @noframes
  12. //
  13. // @match             https://*.imdb.com/title/tt*
  14. // ==/UserScript==
  15.  
  16. function yp_imdb_copy_title() {
  17.     "use strict";
  18.     const myName = `imdbCopyTitle`;
  19.  
  20.     let imdbID       = /\/tt(\d+)\//.exec( document.URL );
  21.     let titleElement = document.querySelector( '.title_wrapper > h1:nth-child(1)' );
  22.  
  23.     if ( titleElement && imdbID ) {
  24.  
  25.         let newTitle = ( titleElement.innerText + " (tt" + imdbID[1] + ")" )
  26.             .replace(/:/g, ' - ')
  27.             .replace(/\s+/g, ' ')
  28.             .replace(/^\s+/g, '')
  29.             .replace(/\s+$/g, '');
  30.  
  31.         titleElement.innerText = newTitle;
  32.         console.log( `${myName} - Suggested title: ${newTitle}` );
  33.         GM_setClipboard( newTitle );
  34.  
  35.     } else {
  36.  
  37.         console.log( `${myName} - Something went wrong.` );
  38.         console.log( `${myName} - Title[${titleElement}] ID[${imdbID}]`);
  39.  
  40.     }
  41. }
  42.  
  43. yp_imdb_copy_title();
  44.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement