Skip to content

Instantly share code, notes, and snippets.

@aachyee
Last active December 24, 2023 22:34
Show Gist options
  • Select an option

  • Save aachyee/a112ce2f45edc2c4468b1d1ff9e24d87 to your computer and use it in GitHub Desktop.

Select an option

Save aachyee/a112ce2f45edc2c4468b1d1ff9e24d87 to your computer and use it in GitHub Desktop.
This user script recovers pixiv trial unlinked history items for Tampermonkey.
// ==UserScript==
// @name Pixiv trial history recovery
// @namespace http://tampermonkey.net/
// @version 2023-12-24
// @description Try to recover Pixiv trial unlinked history items.
// @author aachyee
// @match https://www.pixiv.net/history.php
// @icon https://www.google.com/s2/favicons?sz=64&domain=pixiv.net
// @grant none
// ==/UserScript==
(function() {
'use strict';
// console.log('Pixiv trial history recovery script start.');
// HTMLのbodyエレメントが閉じていないのでDOMContentLoadedは起きない
window.addEventListener("load", (event) => { // load or DOMContentLoaded
console.log('load!');
const target = document.querySelector("div._history-items");
// console.log( 'target: ', target );
const observer = new MutationObserver((mutationsList, observer) => {
mutationsList.forEach(mutation => {
// console.log('DOM changed:', mutation);
if (mutation.type === "childList") {
// console.log("A child node has been added or removed.");
mutation.addedNodes.forEach(node => {
// console.log(node, "has been added.");
// console.log(node.tagName, "has been added");
if (node.tagName === 'SPAN' && node.className === '_history-item trial') {
// console.log('background-image:', node.style.backgroundImage);
const m = node.style.backgroundImage.match(/\/([0-9]+)_/);
if (m[1]) {
const fragment = document.createDocumentFragment();
const anchor = document.createElement("a");
const div = document.createElement("div");
anchor.href = `/artworks/${m[1]}`;
anchor.target = "_blank";
anchor.className = "_history-item show-detail list-ite";
anchor.rel = "noreferrer";
anchor.style.backgroundImage = node.style.backgroundImage;
anchor.textContent = "";//改行(CR)を出力したい場合はinnerText
div.className = "status";
anchor.appendChild(div);
fragment.appendChild(anchor);
node.parentNode.insertBefore(anchor,node);
node.parentNode.removeChild(node);
}
}
});
}
});
});
observer.observe(target, {
childList: true // , subtree: true, characterData: true, characterDataOldValue: true, attributeOldValue: true
});
});
// console.log('Pixiv trial history recovery script running.');
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment