Skip to content

Instantly share code, notes, and snippets.

@kebien6020
Last active April 30, 2019 04:22
Show Gist options
  • Save kebien6020/f6489944130a8d891dbebffbe4388b08 to your computer and use it in GitHub Desktop.
Save kebien6020/f6489944130a8d891dbebffbe4388b08 to your computer and use it in GitHub Desktop.
Go to the old site at the current image clicking an orange circle at the bottom. This circle turns blue if the image has notes.
// ==UserScript==
// @name Button to old page
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Show a button to go to the old site!
// @author Baku
// @updateURL https://gist.github.com/kebien6020/f6489944130a8d891dbebffbe4388b08/raw/SankakuButtonToOldSite.user.js
// @downloadURL https://gist.github.com/kebien6020/f6489944130a8d891dbebffbe4388b08/raw/SankakuButtonToOldSite.user.js
// @match https://beta.sankakucomplex.com/*
// @grant none
// @require https://unpkg.com/xhook@latest/dist/xhook.min.js
// @run-at document-start
// ==/UserScript==
//patch history object
(function(history){
var pushState = history.pushState;
history.pushState = function(state) {
const retval = pushState.apply(history, arguments);
if (typeof history.onpushstate == "function") {
history.onpushstate({state: state});
}
return retval;
};
})(window.history);
(function(window, history) {
'use strict';
const CLASSNAME = 'baku-oldpage-container'
history.onpushstate = window.onpopstate = window.onload = function () {
const re = /\/post\/show\/(\d+)/
const matches = re.exec(window.location.pathname)
if (matches) {
const id = matches[1]
const notesClass = window.postsWithNotes && window.postsWithNotes.indexOf(id) !== -1 ? ' notes' : ''
const button = `
<style>
.${CLASSNAME} {
width: 100%;
pointer-events: none;
}
.${CLASSNAME} a {
position: fixed;
display:block;
bottom: 10px;
right: 10px;
width: 30px;
height: 30px;
background-color: orange;
border-radius: 50%;
z-index: 10000;
pointer-events: auto;
}
.${CLASSNAME} a.notes {
background-color: #2196F3;
}
@media (max-width: 992px) {
.${CLASSNAME} a {
left: 50%;
margin-left: -15px;
}
}
</style>
<a
class="${notesClass}"
href="//chan.sankakucomplex.com/post/show/${id}"
target="_blank"
>
</a>`
let container = document.querySelector(`div.${CLASSNAME}`)
if (!container) {
container = document.createElement('div')
container.classList.add(CLASSNAME)
}
console.log('Updated redirect to oldpage with id = ', id)
container.innerHTML = button
document.body.append(container)
}
}
})(window, window.history);
// Save posts with notes
(function () {
window.postsWithNotes = []
//modify 'responseText' of 'example2.txt'
xhook.after(function(request, response) {
if(request.url.match(/posts.*$/)) {
let posts = null
try {
posts = JSON.parse(response.text)
} catch (e) {}
if (posts !== null && Array.isArray(posts)) {
for (let i = 0; i < posts.length; ++i) {
if (Array.isArray(posts[i].tags)) {
if (posts[i].has_notes) {
window.postsWithNotes.push(String(posts[i].id))
}
}
}
response.text = JSON.stringify(posts)
}
}
});
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment