Advertisement
Yunga

IMDB Bookmarklet

Jan 22nd, 2020
301
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Copy IMDB Title and ID to clipboard
  2.  
  3. javascript:(function(){
  4.  
  5.     let titleElement = document.querySelector( '.title_wrapper > h1:nth-child(1)' );
  6.     let imdbID = /\/tt(\d+)\//.exec( document.URL );
  7.    
  8.     if ( titleElement && imdbID ) {
  9.  
  10.         let newTitle = ( titleElement.innerText + " (tt" + imdbID[1] + ")" )
  11.             .replace(/:/g, ' - ')
  12.             .replace(/\s+/g, ' ')
  13.             .replace(/^\s+/g, '')
  14.             .replace(/\s+$/g, '');
  15.  
  16.         console.log( 'IMDB Bookmarklet - Suggested title: ' + newTitle );
  17.  
  18.         navigator.clipboard.writeText( newTitle ).then(
  19.             status => console.log( 'IMDB Bookmarklet - Copied: ' + status ),
  20.             status => console.log( 'IMDB Bookmarklet - Not copied: ' + status )
  21.         ).catch( e => console.log( 'IMDB Bookmarklet - Could not copy: ' + e ) );
  22.  
  23.     } else {
  24.  
  25.         console.log( 'IMDB Bookmarklet - Something went wrong.' );
  26.         console.log( 'Title Element:');
  27.         console.log( titleElement );
  28.         console.log( 'IMDB ID:');
  29.         console.log( imdbID );
  30.  
  31.     }
  32.  
  33. })()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement