Skip to content

Instantly share code, notes, and snippets.

@maxgalbu
Last active July 6, 2016 21:43
Show Gist options
  • Save maxgalbu/65756005cf09209d6a6a6dc6f9c5234e to your computer and use it in GitHub Desktop.
Save maxgalbu/65756005cf09209d6a6a6dc6f9c5234e to your computer and use it in GitHub Desktop.
// ==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 */
function poll() {
let films = document.getElementsByClassName("film");
for (let film of films) {
let h2Element= film.getElementsByTagName("h2")[0];
let anchorElement = h2Element.getElementsByTagName("a")[0];
if (anchorElement.getAttribute("vote_obtained") == 1) {
continue;
}
let title = anchorElement.getAttribute("title");
let ajax = new XMLHttpRequest();
ajax.addEventListener("load", function() {
let data = JSON.parse(this.responseText);
let filmData = data.results ? data.results[0] : null;
if (filmData) {
anchorElement.innerHTML = "("+filmData.vote_average+") " + anchorElement.innerHTML;
anchorElement.setAttribute("vote_obtained", "1");
}
});
ajax.open("GET", 'http://api.themoviedb.org/3/search/movie?api_key=edfc3215a4d2762d3f4df32bf53595e4&query='+encodeURIComponent(title));
ajax.send();
}
}
setInterval(poll, 4000);
/* 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