Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name PTP Box Office Detector V2
- // @namespace PTPBOD_abc123
- // @version 0.2b
- // @description Finds a film's box office information when possible
- // @author abc123
- // @include https://passthepopcorn.me/torrents.php?id=*
- // @grant GM_xmlhttpRequest
- // @connect www.imdb.com
- // ==/UserScript==
- /*****************
- * AUTHOR'S NOTE *
- *****************
- * This script is designed for fetching box office information for any
- * given movie being viewed on PassThePopcorn. It does this by querying
- * IMDB and pulling their Box Office data.
- *
- * Big thanks to HostileThingy to made a version of this that works with
- * wikipedia.
- */
- /***********
- * OPTIONS *
- ***********/
- // uncomment (or add) values you wish to hide
- var boHideArr = [];
- // boHideArr.push('Budget');
- // boHideArr.push('Opening Weekend USA');
- // boHideArr.push('Gross USA');
- // boHideArr.push('Worldwide Gross');
- /*****************
- * FUNCTIONALITY *
- *****************/
- function queryIMDB(imdbId) {
- GM_xmlhttpRequest({
- method: 'GET',
- url: 'https://www.imdb.com/title/tt'+ imdbId,
- onload: parseIMDB
- });
- }
- function parseIMDB(response) {
- var domparser = new DOMParser();
- var doc = domparser.parseFromString(response.responseText, 'text/html');
- if ( typeof doc !== 'object' ) return false;
- // get movie info panel of PTP
- var parentEl = document.querySelector('#movieinfo > .panel__body');
- if ( ! parentEl ) return false;
- // find detail area of IMDB
- var details = doc.querySelector('#titleDetails');
- if ( ! details ) return false;
- var inBO = false;
- var detail = details.querySelectorAll('.subheading, div.txt-block');
- // NOTE: forEach on nodeList won't work on early browsers... use Array.prototype
- detail.forEach(function(node) {
- if ( node.classList.contains('subheading') ) {
- inBO = !! (node.innerText === 'Box Office');
- return false;
- }
- if ( inBO ) {
- appendIMDBInfo(parentEl, node);
- }
- });
- }
- function appendIMDBInfo(parentEl, node) {
- // find box office label
- var labelSrc = node.querySelector('h4');
- if ( ! labelSrc ) return false;
- var label = labelSrc.innerText;
- node.removeChild(labelSrc);
- // find box office detail (extra info)
- var detailSrc = node.querySelector('span');
- if ( detailSrc ) {
- node.removeChild(detailSrc);
- }
- var value = node.innerText;
- // do any extra display modifications here
- label = label.replace(/Cumulative /, '');
- value = value.replace(/,\s*$/, '');
- // only show budget and worldwide gross
- if ( ~boHideArr.indexOf(label.replace(':','')) ) return false;
- // output to screen
- var labelDiv = document.createElement('div');
- var labelStrong = document.createElement('strong');
- labelStrong.innerHTML = label;
- labelDiv.appendChild(labelStrong);
- labelDiv.innerHTML += value;
- parentEl.appendChild(labelDiv);
- }
- (function() {
- 'use strict';
- var imdbLink = document.getElementById('imdb-title-link');
- if ( ! imdbLink ) return false;
- var imdbMatch = imdbLink.href.match(/tt(\d+)/);
- if ( ! imdbMatch ) return false;
- queryIMDB(imdbMatch[1]);
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement