Last active
December 18, 2021 16:34
-
-
Save joshparkerj/0460c070ffc8ddc6362c8d302abbdd62 to your computer and use it in GitHub Desktop.
get cross origin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ==UserScript== | |
| // @name get cross origin | |
| // @namespace http://tampermonkey.net/ | |
| // @version 0.1 | |
| // @description try to take over the world! | |
| // @author Josh Parker | |
| // @match https://www.imdb.com/search/title/?year=2021&sort=num_votes,desc | |
| // @icon https://www.google.com/s2/favicons?domain=imdb.com | |
| // @connect www.rottentomatoes.com | |
| // @grant GM.xmlHttpRequest | |
| // ==/UserScript== | |
| (function getRT() { | |
| const rtRoot = 'https://www.rottentomatoes.com'; | |
| // const certifiedFresh = | |
| // '/assets/pizza-pie/images/icons/tomatometer/certified_fresh-notext.56a89734a59.svg'; | |
| // const fresh = '/assets/pizza-pie/images/icons/tomatometer/tomatometer-fresh.149b5e8adc3.svg'; | |
| // const rotten = '/assets/pizza-pie/images/icons/tomatometer/tomatometer-rotten.f1ef4f02ce3.svg'; | |
| const rtSearch = '/search?search='; | |
| const works = [...document.querySelectorAll('.lister-item')]; | |
| const parser = new DOMParser(); | |
| works.forEach((work) => { | |
| const { title, year } = work.querySelector('h3.lister-item-header').innerText.match(/^(?<number>\S+) (?<title>.*) (?<year>\([^)]+\))$/).groups; | |
| // console.log(title); | |
| // console.log(year); | |
| const isTV = year.match(/[-–]/); | |
| // console.log(isTV); | |
| const topBilled = work.querySelector('.lister-item-content > p > a[href^="/name"]').innerText; | |
| const searchUrl = `${rtRoot}${rtSearch}${title} ${topBilled}`.replaceAll(' ', '%20'); | |
| console.log(searchUrl); | |
| GM.xmlHttpRequest({ | |
| method: 'GET', | |
| url: searchUrl, | |
| onload({ responseText }) { | |
| const dom = parser.parseFromString(responseText, 'text/html'); | |
| let spmr; | |
| if (isTV) spmr = dom.querySelector('search-page-result[type=tv] search-page-media-row'); | |
| else spmr = dom.querySelector('search-page-media-row'); | |
| const state = spmr.getAttribute('tomatometerstate'); | |
| const score = spmr.getAttribute('tomatometerscore'); | |
| const rtRating = document.createElement('div'); | |
| const rtRatingContent = document.createElement('span'); | |
| const rtTitle = spmr.querySelector('a[slot=title]').textContent.trim(); | |
| rtRatingContent.innerText = `Rotten tomatoes score for ${rtTitle}: ${score} (${state})`; | |
| rtRating.classList.add('inline-block'); | |
| rtRating.classList.add('ratings-tomatometer'); | |
| rtRating.appendChild(rtRatingContent); | |
| work.querySelector('div.ratings-bar').appendChild(rtRating); | |
| }, | |
| }); | |
| }); | |
| }()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment