Skip to content

Instantly share code, notes, and snippets.

@esperecyan
Last active January 11, 2020 00:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save esperecyan/5db524e125cf6ebd4e2076078da021e6 to your computer and use it in GitHub Desktop.
Save esperecyan/5db524e125cf6ebd4e2076078da021e6 to your computer and use it in GitHub Desktop.
Firefox 72以降で動作。7つの定数値を書き替え後、ブラウザーコンソールにコピペして実行。
(async function () {
const FAVICON_URI = NetUtil.newURI('https://www.pixiv.net/favicon.ico');
const PRINCIPAL = Services.scriptSecurityManager.createContentPrincipal(NetUtil.newURI('https://www.pixiv.net/artworks/'), {});
const OLD_URL_SEARCH_TERMS = 'https://www.pixiv.net/member_illust.php?mode=medium&illust_id=';
const OLD_URL_PATTERN = /^https:\/\/www\.pixiv\.net\/member_illust.php\?mode=medium&illust_id=[0-9]+$/;
const NEW_URL_SEARCH_TERMS = 'https://www.pixiv.net/artworks/';
const NEW_URL_PATTERN = /^https:\/\/www\.pixiv\.net\/artworks\//;
const REPLACE_PATTERN = [/\/member_illust\.php\?mode=medium&illust_id=/, '/artworks/'];
const query = PlacesUtils.history.getNewQuery();
const options = PlacesUtils.history.getNewQueryOptions();
options.includeHidden = true;
const newURLs = [];
query.searchTerms = NEW_URL_SEARCH_TERMS;
let root = PlacesUtils.history.executeQuery(query, options).root;
root.containerOpen = true;
for (let i = 0, l = root.childCount; i < l; i++) {
const url = root.getChild(i).uri;
if (NEW_URL_PATTERN.test(url)) {
newURLs.push(url);
}
}
root.containerOpen = false;
const oldHistoryItems = [];
query.searchTerms = OLD_URL_SEARCH_TERMS;
root = PlacesUtils.history.executeQuery(query, options).root;
root.containerOpen = true;
for (let i = 0, l = root.childCount; i < l; i++) {
const node = root.getChild(i);
const url = node.uri;
if (OLD_URL_PATTERN.test(url)) {
oldHistoryItems.push({
url,
title: node.title,
lastVisitTime: node.time,
});
}
}
root.containerOpen = false;
let i = 0;
for (const oldHistoryItem of oldHistoryItems) {
if (i % 100 === 0) {
console.info(`${i}件 ⁄ ${oldHistoryItems.length}件`);
}
const newURL = oldHistoryItem.url.replace(...REPLACE_PATTERN);
if (!newURLs.includes(newURL)) {
await PlacesUtils.history.insert({
title: oldHistoryItem.title,
url: newURL,
visits: [{transition: PlacesUtils.history.TRANSITION_LINK, date: PlacesUtils.toDate(oldHistoryItem.lastVisitTime)}],
});
PlacesUtils.favicons.setAndFetchFaviconForPage(
NetUtil.newURI(newURL),
FAVICON_URI,
false,
PlacesUtils.favicons.FAVICON_LOAD_NON_PRIVATE,
null,
PRINCIPAL
);
}
await PlacesUtils.history.remove(oldHistoryItem.url);
i++;
}
console.info(`${oldHistoryItems.length}件の履歴を置き換えました`);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment