Created
October 21, 2016 23:47
-
-
Save maxgalbu/8b19126ba01c84b72ff11dd899475f21 to your computer and use it in GitHub Desktop.
Greasemonkey/tampermonkey plugin that gets the imdb rating for the movies in the SkyGo.it pages
This file contains 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 New ES6-Userscript | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description shows how to use babel compiler | |
// @author You | |
// @require https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.6.15/browser-polyfill.min.js | |
// @require https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.6.15/browser.min.js | |
// @match http://*/* | |
// ==/UserScript== | |
/* jshint ignore:start */ | |
var inline_src = (<><![CDATA[ | |
/* jshint ignore:end */ | |
/* jshint esnext: true */ | |
let films = document.getElementsByClassName("film"); | |
for (let film of films) { | |
let h2Element= film.getElementsByTagName("h2")[0]; | |
let anchorElement = h2Element.getElementsByTagName("a")[0]; | |
let title = anchorElement.getAttribute("title"); | |
let ajax = new XMLHttpRequest(); | |
ajax.addEventListener("load", function() { | |
let data = this.responseText; | |
let filmData = data.Search[0]; | |
if (filmData) { | |
let filmId = filmData.imdbId; | |
let ajax2 = new XMLHttpRequest(); | |
ajax2.addEventListener("load", function() { | |
let fullFilmData = JSON.parse(this.responseText); | |
if (fullFilmData) { | |
let vote = filmData.imdbRating; | |
anchorElement.innerHTML += " ("+vote+")"; | |
} | |
}); | |
ajax2.open("GET", "http://www.omdbapi.com/?i="+titleId); | |
ajax2.send(); | |
} | |
}); | |
ajax.open("GET", "http://www.omdbapi.com/?s="+encodeURIComponent(title)); | |
ajax.send(); | |
} | |
/* jshint ignore:start */ | |
]]></>).toString(); | |
var c = babel.transform(inline_src); | |
eval(c.code); | |
/* jshint ignore:end */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment