Last active
October 6, 2021 01:32
-
-
Save ailispaw/af6107e6a8760967f72818126065ef70 to your computer and use it in GitHub Desktop.
Taberareloo Patch version of Tumblr Timestamp
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
// ==Taberareloo== | |
// { | |
// "name" : "Add Timestamp into Posts on Tumblr Dashboard" | |
// , "description" : "Add Timestamp into Posts on Tumblr Dashboard" | |
// , "include" : ["content"] | |
// , "match" : ["*://www.tumblr.com/*"] | |
// , "version" : "0.0.8" | |
// , "downloadURL" : "https://gist.githubusercontent.com/ailispaw/af6107e6a8760967f72818126065ef70/raw/userscript.tumblr.timestamp.tbrl.js" | |
// } | |
// ==/Taberareloo== | |
(function() { | |
var script = $X("//body/script[@nonce]")[0].text; | |
var validJSON = script.match(/window\['___INITIAL_STATE___'\] ?= ?(.*?);\n/)[1]; | |
validJSON = validJSON.replace(/:undefined,/g, ':null,'); | |
validJSON = validJSON.replace(/:undefined]/g, ':null]'); | |
validJSON = validJSON.replace(/:undefined}/g, ':null}'); | |
var STATE = JSON.parse(validJSON); | |
console.log(STATE); | |
if (STATE && STATE.isLoggedIn.isLoggedIn) { | |
request(STATE.cssMapUrl, { responseType : 'json' }).then(function (res) { | |
var cssMap = res.response; | |
console.log(cssMap); | |
// Wait for building the timeline | |
var timer = setInterval(function () { | |
var timeline = null; | |
for ( i = 0 ; i < cssMap.timeline.length ; i++ ) { | |
timeline = $X("//div[@class='" + cssMap.timeline[i] + "']/div[div[@data-id]]")[0]; | |
if ( timeline ) { | |
break; | |
} | |
} | |
if (!timeline) { | |
return; | |
} | |
clearInterval(timer); | |
go_timestamp(timeline); | |
timeline.addEventListener('DOMSubtreeModified', function (e) { | |
if (e.target === timeline) { | |
setTimeout(function () { | |
go_timestamp(timeline); | |
}, 500); | |
} | |
}, false); | |
}, 500); | |
}); | |
} | |
function go_timestamp (timeline) { | |
$X("./div[@data-id]", timeline).forEach(function (post) { | |
var article = $X(".//article", post)[0]; | |
var footer = $X(".//footer", article)[0]; | |
var timestamp_link = $X("./header/a[@aria-label='Permalink']", article)[0]; | |
if (!timestamp_link) { | |
return; | |
} | |
var time_stamp_node = $N('div', { | |
class : 'c47_timestamp', | |
style : 'font-size: 16px; padding-left: var(--post-padding);' | |
}, timestamp_link.getAttribute("title").replace("View post - ", "")); | |
if (footer) { | |
if (!$X("./div[@class='c47_timestamp']", footer)[0]) { | |
footer.insertBefore(time_stamp_node, footer.childNodes[0]); | |
} | |
} | |
}); | |
}; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment