Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name RF
- // @version 0.5.7
- // @description Extract imdb data into ILC format
- // @author Chameleon + dimi401
- // @include http*://*imdb.com/title/tt*
- // @include http*://pretome.info/details.php?id=*
- // @match file:///home/dim/test/testpage.html
- // @updateURL https://pastebin.com/MVi83dqj
- // @downloadURL https://pastebin.com/MVi83dqj
- // @grant GM_getValue
- // @grant GM_setValue
- // ==/UserScript==
- //setTimeout(
- //function() {
- // window.scrollTo(0,document.body.scrollHeight); }
- //, 0);
- (function() {
- 'use strict';
- //IMDB BUTTON
- if (window.location.href.includes('www.imdb.com')) {
- //autorun check
- if (GM_getValue('auto')==1) {
- collect();
- }
- var a=document.createElement('a');
- a.innerHTML='RF';
- a.addEventListener('click', collect);
- a.href='javascript:void(0);';
- var place=document.getElementsByClassName('subtext')[0];
- var span=document.createElement('span');
- span.setAttribute('class', 'ghost');
- span.innerHTML='|';
- place.appendChild(span);
- place.appendChild(a);
- }
- //SCENE SITE BUTTON\
- if (window.location.href.includes('pretome')) {
- var a=document.createElement('a');
- a.innerHTML='ILC Extract';
- a.addEventListener('click', fill_text);
- a.href='javascript:void(0);';
- var place=document.getElementsByClassName('mf_middle_middle')[1];
- var span=document.createElement('span');
- span.setAttribute('class', 'ghost');
- span.innerHTML='|';
- place.appendChild(span);
- place.appendChild(a);
- }
- })();
- function fill_text()
- {
- GM_setValue('auto',1);
- GM_setValue('fill',0);
- if ( document.body.innerHTML.match(/www.imdb.com\/title\/tt[0-9]*/) != null ) {
- url = document.body.innerHTML.match(/www.imdb.com\/title\/tt[0-9]*/)[0];
- url = 'https://' + url + '/';
- window.open(url);
- interval = setInterval(checkfill,1500);
- }
- }
- function checkfill()
- {
- if ( GM_getValue('fill') != 0) {
- vard = GM_getValue('fill');
- document.getElementById('text').value = vard;
- clearInterval(interval);
- }
- }
- function close()
- {
- document.body.removeChild(document.getElementById('ilc_extract'));
- }
- function collect()
- {
- // Get AKAs before running the collect on the main page
- var imdbId=window.location.href.split('/title/tt')[1].split('/')[0];
- var xhr = new XMLHttpRequest();
- xhr.open('GET', "https://www.imdb.com/title/tt"+imdbId+"/releaseinfo");
- xhr.onreadystatechange = function()
- {
- if(xhr.readyState == 4 && xhr.status==200)
- {
- var newDoc=document.implementation.createHTMLDocument();
- newDoc.body.innerHTML=xhr.responseText;
- try
- {
- var trs=newDoc.getElementById('akas').nextElementSibling.getElementsByTagName('tr');
- var akas=[];
- for(var i=0; i<trs.length; i++)
- {
- var tds=trs[i].getElementsByTagName('td');
- var found=false;
- for(var j=0; j<akas.length; j++)
- {
- if(akas[j].title == tds[1].textContent)
- {
- found=true;
- break;
- }
- }
- if(found)
- continue;
- akas.push({name:tds[0].textContent, title:tds[1].textContent});
- }
- collect1(akas);
- }
- catch(e){ console.log(e); }
- }
- }
- xhr.send();
- }
- function collect1(akas)
- {
- var div=document.getElementById('ilc_extract');
- if(!div)
- {
- div=document.createElement('div');
- div.id='ilc_extract';
- div.setAttribute('style', 'background:rgba(0,0,0,0.8); width: 1200px; min-height:800px; top:200px; position: absolute; left:0; right:0; margin:auto; z-index:200;');
- document.body.appendChild(div);
- }
- var textarea=document.createElement('textarea');
- textarea.setAttribute('style', 'width: calc(100% - 15px); margin:5px; border:none; resize:none;');
- div.appendChild(textarea);
- var a=document.createElement('a');
- a.innerHTML='Close';
- a.href='javascript:void(0)';
- a.addEventListener('click', close);
- div.appendChild(a);
- a.setAttribute('style', 'display:block; text-align:center; color:white; margin:10px;');
- var movie={};
- var h1=document.getElementsByTagName('h1')[0];
- movie.title=h1.firstChild.textContent.trim();
- if (document.getElementsByClassName('poster')[0]!=null){
- movie.poster=document.getElementsByClassName('poster')[0].getElementsByTagName('img')[0].src;
- //above is the image link from the main page
- if ( movie.poster.match(/https:\/\/m.media-amazon.com.*V1_/) != null ) {
- movie.poster=movie.poster.match(/https:\/\/m.media-amazon.com.*V1_/)[0];
- movie.poster=movie.poster + 'SY600.jpg';
- }
- else {
- //here include additional code for more full resolution posters
- }
- }
- if (h1.firstElementChild!=null){
- movie.year=parseInt(h1.firstElementChild.textContent.split('(')[1]);
- }
- else{
- movie.year=extract_release_date('Release Date:')
- }
- movie.id=window.location.href.split('/title/tt')[1].split('/')[0];
- if(document.getElementsByTagName('time')[0]!=null){
- movie.runtime=document.getElementsByTagName('time')[0].textContent.trim();
- }
- movie.genres=extract('Genres:', 'title?genres=');
- movie.languages=extract('Language:', 'primary_language');
- movie.countries=extract('Country:', 'country_of_origin');
- if (document.getElementById('titleStoryLine').getElementsByTagName('p')[0] != undefined) {
- movie.plot = document.getElementById('titleStoryLine').getElementsByTagName('p')[0].getElementsByTagName('span')[0].textContent.trim();
- }
- movie.directors=extract('Director:', 'name/nm');
- movie.writers=extract('Writers:', 'name/nm');
- movie.creators=extract('Creators:', 'name/nm');
- movie.cast=[];
- if (document.getElementsByClassName('cast_list')[0]!=undefined) {
- var trs=document.getElementsByClassName('cast_list')[0].getElementsByTagName('tr');
- for(var i=1; i<trs.length; i++)
- {
- var actor={};
- var tds=trs[i].getElementsByTagName('td');
- if (tds[1]!=undefined) {
- var a=tds[1].getElementsByTagName('a')[0];
- actor.link=a.href;
- if(actor.link.indexOf('name/nm')==-1)
- {
- continue;
- }
- actor.name=a.textContent.trim();
- actor.role=tds[3].textContent.split('\n')[1].trim();
- movie.cast.push(actor);
- }
- }
- }
- textarea.innerHTML+="[size=6]"+movie.title+ "[/size] | [url=https://retroflix.club/forums.php?action=search&keywords=tt"+movie.id+"]Actors[/url]\n";
- if(movie.poster){
- textarea.innerHTML+="[img]"+movie.poster+"[/img]\n";
- }
- textarea.innerHTML+="https://www.imdb.com/title/tt"+movie.id+"\n";
- textarea.innerHTML+="\n";
- textarea.innerHTML+="[b]Year:[/b] "+movie.year+"\n";
- textarea.innerHTML+="[b]Runtime:[/b] "+movie.runtime+"\n";
- textarea.innerHTML+="[b]Genre";
- if(movie.genres.length>1)
- textarea.innerHTML+="s";
- textarea.innerHTML+=":[/b] "+join(movie.genres)+"\n";
- textarea.innerHTML+="[b]Language"
- if(movie.languages.length>1)
- textarea.innerHTML+="s";
- textarea.innerHTML+=":[/b] "+join(movie.languages)+"\n";
- textarea.innerHTML+="[b]Countr"
- if(movie.countries.length>1)
- textarea.innerHTML+="ies";
- else
- textarea.innerHTML+='y';
- textarea.innerHTML+=":[/b] "+join(movie.countries)+"\n";
- textarea.innerHTML+="[b]Plot:[/b] "+movie.plot+"\n";
- if(movie.directors.length>0){
- textarea.innerHTML+="\n";
- textarea.innerHTML+="[b]Director"
- if(movie.directors.length>1)
- textarea.innerHTML+="s";
- textarea.innerHTML+=":[/b]\n";
- for(var i=0; i<movie.directors.length; i++)
- {
- var d=movie.directors[i];
- textarea.innerHTML+='[url='+d.link+']'+d.name+'[/url]\n';
- }
- }
- if(movie.writers.length>0){
- textarea.innerHTML+="\n";
- textarea.innerHTML+="[b]Writer"
- if(movie.writers.length>1)
- textarea.innerHTML+="s";
- textarea.innerHTML+=":[/b]\n";
- for(var i=0; i<movie.writers.length; i++)
- {
- var w=movie.writers[i];
- textarea.innerHTML+='[url='+w.link+']'+w.name+'[/url]\n';
- }
- }
- if(movie.creators.length>0){
- textarea.innerHTML+="\n";
- textarea.innerHTML+="[b]Creator"
- if(movie.creators.length>1)
- textarea.innerHTML+="s";
- textarea.innerHTML+=":[/b]\n";
- for(var i=0; i<movie.creators.length; i++)
- {
- var w=movie.creators[i];
- textarea.innerHTML+='[url='+w.link+']'+w.name+'[/url]\n';
- }
- }
- if (movie.cast.length>0){
- textarea.innerHTML+="\n";
- textarea.innerHTML+="[b]Cast:[/b]\n";
- for(var i=0; i<movie.cast.length; i++)
- {
- var c=movie.cast[i];
- textarea.innerHTML+='[url='+c.link+']'+c.name+'[/url] - '+c.role+'\n';
- }
- }
- //textarea.innerHTML+="\n";
- //textarea.innerHTML+="\n";
- if(akas.length>0)
- {
- textarea.innerHTML+='\n';
- textarea.innerHTML+="[b]AKAs:[/b]\n";
- for(var i=0; i<akas.length; i++)
- {
- textarea.innerHTML+=akas[i].title.trim()+'\n';
- }
- }
- //textarea.innerHTML+="I am wondering if adding the movie information is worth it. Send me a PM if you think I should continue.";
- textarea.style.height=textarea.scrollHeight+'px';
- //RESET AUTO VALUE
- GM_setValue('fill',textarea.innerHTML);
- //vard = GM_getValue('testing');
- //console.log(vard);
- //Copyt to clipboard
- textarea.select();
- document.execCommand('copy');
- if (GM_getValue('auto') == 1 ) {
- GM_setValue('auto',0)
- window.close();
- }
- //Unselect Everything
- document.getSelection().removeAllRanges();
- //document.getSelection().addRange(selected); // dimi, not sure what you were doing here but 'selected' doesn't exist?
- }
- function join(list)
- {
- if(list.length==0)
- return "";
- var str=list[0].name;
- for(var i=1; i<list.length; i++)
- {
- str+=', '+list[i].name;
- }
- return str;
- }
- function extract(h4_text, restrict)
- {
- var holder=false;
- var h4s=document.getElementsByTagName('h4');
- var res=[];
- for(var i=0; i<h4s.length; i++)
- {
- var h4=h4s[i];
- if(h4.textContent.substr(0,5)==h4_text.substr(0,5)&&h4.textContent.substr(-1)==h4_text.substr(-1))
- {
- holder=h4.parentNode;
- break;
- }
- }
- if(holder)
- {
- var as=holder.getElementsByTagName('a');
- for(var i=0; i<as.length; i++)
- {
- if(as[i].href.indexOf(restrict)==-1)
- {
- continue;
- }
- res.push({name:as[i].textContent.trim(), link:as[i].href});
- }
- }
- return res;
- }
- function extract_release_date(h4_text)
- {
- var h4s=document.getElementsByTagName('h4');
- var year='Not Available';
- for(var i=0; i<h4s.length; i++)
- {
- var h4=h4s[i];
- if(h4.textContent.substr(0,5)==h4_text.substr(0,5)&&h4.textContent.substr(-1)==h4_text.substr(-1))
- {
- if(h4.nextSibling.textContent.match(/(19|20)[0-9][0-9]/g)!=null){
- year=h4.nextSibling.textContent.match(/(19|20)[0-9][0-9]/g)[0];
- break;
- }
- }
- }
- return year;;
- }
Advertisement
Add Comment
Please, Sign In to add comment