Last active
March 31, 2021 20:06
-
-
Save VDK/034ea71a6a0317b76623eb4dc22113f9 to your computer and use it in GitHub Desktop.
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 MUBI id | |
// @namespace https://mubi.com/ | |
// @version 0.2 | |
// @description show mubi id in the interface | |
// @author VDK | |
// @match https://mubi.com/* | |
// @grant none | |
// ==/UserScript== | |
function docReady(fn) { | |
// see if DOM is already available | |
if (document.readyState === "complete" || document.readyState === "interactive") { | |
// call on next available tick | |
setTimeout(fn, 1); | |
} else { | |
document.addEventListener("DOMContentLoaded", fn); | |
} | |
} | |
(function() { | |
'use strict'; | |
docReady(function() { | |
var id = null; | |
var json =JSON.parse( document.getElementById('__NEXT_DATA__').text); | |
if (json['page'] == "/cast/[castSlug]"){ | |
id = json['props']["initialProps"]["pageProps"]["castMember"]['id']; | |
document.getElementsByClassName('css-5s0yq')[0].appendChild(createLink(id, "li", "css-16o045c elv6jbt6")); | |
} | |
else if(json['page'] == "/films/[filmSlug]"){ | |
id = json['props']["initialProps"]["pageProps"]["film"]['id']; | |
document.getElementsByClassName('css-1717uzm')[0].appendChild(createLink(id, "div", "css-1tzeee1 e1up1td00")); | |
} | |
}); | |
})(); | |
function createLink(id, element, class_name){ | |
element = document.createElement(element); | |
element.setAttribute("class",class_name); | |
var a = document.createElement("a"); | |
a.innerHTML = id; | |
a.setAttribute("href", "#"); | |
a.setAttribute("class", "css-1s3qbnc"); | |
element.appendChild(a) | |
return element; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment