Skip to content

Instantly share code, notes, and snippets.

@colt365
Last active January 3, 2024 10:52
Show Gist options
  • Select an option

  • Save colt365/6472473 to your computer and use it in GitHub Desktop.

Select an option

Save colt365/6472473 to your computer and use it in GitHub Desktop.
user.js
// ==UserScript==
// @name Bilibili 收藏夹备份
// @namespace https://gist.github.com/colt365/
// @description 将 Bilibili 收藏夹备份为 JSON
// @match https://space.bilibili.com/*
// @version 1.0.1.20230714
// @grant none
// ==/UserScript==
let box, favData, run = false;
const ITEM_PER_PAGE = 20;
let main = function() {
if (run) {
return;
} else {
run = true;
}
let mid = location.toString().match(/space\.bilibili\.com\/\d+/);
if (mid.length < 1) {
console.warn('URL does not match!');
return;
}
mid = mid[0].match(/\d+/)[0];
let request = new XMLHttpRequest();
request.open('GET', `https://api.bilibili.com/x/v3/fav/folder/created/list-all?up_mid=${mid}`);
request.responseType = 'json';
request.withCredentials = true;
request.onload = function() {
favData = request.response.data;
let item = document.createElement('div');
item.className = 'f_download';
item.innerText = '全部收藏夹数据:处理中...';
box.appendChild(item);
for (let i=0;i<favData.count;++i) {
let item = document.createElement('div');
let title = document.createElement('span');
title.innerText = `[${favData.list[i].title}] `;
let t = document.createElement('span');
t.innerText = '等待处理...';
t.className = `f_${favData.list[i].id}`;
item.appendChild(title);
item.appendChild(t);
box.appendChild(item);
}
processFav(0);
}
request.send();
ui();
}
function ui() {
box = document.createElement('div');
box.style = 'border:solid;position:fixed;box-sizing:border-box;width:30%;height:40%;top:0;bottom:0;left:0;right:0;margin:auto;background-color:#fff;opacity:0.9;text-align:center;padding:2em;z-index:99;overflow:auto';
document.body.appendChild(box);
}
function processFav(iFav) {
console.log(`**Processing [${favData.list[iFav].id}]${favData.list[iFav].title}**`);
let nPage = Math.ceil(favData.list[iFav].media_count/ITEM_PER_PAGE);
let fID = favData.list[iFav].id;
let fTitle = favData.list[iFav].title;
let fText = document.querySelector(`.f_${favData.list[iFav].id}`);
let url = function(page) {
return `https://api.bilibili.com/x/v3/fav/resource/list?media_id=${fID}&pn=${page}&ps=${ITEM_PER_PAGE}&order=mtime&type=0&tid=0&platform=web`;
}
function processPage(page) {
console.log(`***Processing page ${page}***`);
fText.innerText = `正在处理第${page}/${nPage}页...`;
let request = new XMLHttpRequest();
request.open('GET', url(page));
request.responseType = 'json';
request.withCredentials = true;
request.onload = function() {
if (request.response.data.medias.length != 20) {
console.warn(`***Page ${page} has ${request.response.data.medias.length} items***`);
}
if (favData.list[iFav].medias) {
favData.list[iFav].medias.push(...request.response.data.medias);
} else {
favData.list[iFav] = request.response.data;
}
if (request.response.data.has_more) {
processPage(page + 1);
} else {
fText.innerText = '处理完成!';
favData.list[iFav].has_more = false;
if (iFav+1 < favData.count) {
processFav(iFav + 1);
} else {
console.log(`*Generating result*`);
let fOut = document.querySelector('.f_download');
fOut.innerText = '全部收藏夹数据:';
let out = JSON.stringify(favData);
let link = document.createElement('a');
link.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(out));
link.setAttribute('download', `Bilibili收藏夹_${new Date(new Date()-new Date().getTimezoneOffset()*60000).toISOString().slice(0,-1)}.json`);
link.innerText = '[点此下载]';
link.style.color='red';
fOut.appendChild(link);
}
}
}
request.send();
};
processPage(1);
}
(function (isLoaded, callback, interval) {
var checkLoadInterval;
function checkLoaded() {
let ret = isLoaded();
if (ret.length) {
window.clearInterval(checkLoadInterval);
setTimeout(() => callback(ret), interval);
}
}
checkLoadInterval = setInterval(checkLoaded, interval);
})(function(){
return document.querySelectorAll('.n-favlist');
}, function(l){
l.forEach(function(d,i){
let a = document.createElement('a');
a.className = d.className;
a.href="javascript:";
a.innerHTML = '<span class="iconfont icon-ic_movedown"></span><span class="n-text">[下载收藏夹]</span>';
a.onclick=main;
d.parentElement.insertBefore(a,d.nextSibling);
});
},1000);
// ==UserScript==
// @name Bilibili disabled video helper
// @version 2
// @grant none
// @match https://space.bilibili.com/*/favlist*
// ==/UserScript==
function afterLoaded(isLoaded, callback, interval) {
let checkLoadInterval;
let count = 0;
let checkLoaded = function() {
let ret = isLoaded();
if (ret) {
callback(ret);
}
}
checkLoadInterval = setInterval(checkLoaded, interval);
}
function callback(lis) {
[...lis].forEach(li=>{
let title = li.querySelector('a.title');
if(!title) return;
let div = document.createElement('div');
let author = li.querySelector('.author').innerText;
div.innerText = li.getAttribute('data-aid') + ' (' + author + ')';
div.className = 'title';
li.insertBefore(div, title.nextSibling);
title.remove();
});
}
afterLoaded(function(){return document.querySelectorAll('ul.fav-video-list li.disabled');}, callback, 3000);
// ==UserScript==
// @name Feedly Customization
// @namespace http://userscripts.org/users/colt365
// @description Customization for Feedly.
// @include https://feedly.com/*
// @version 1.2.0.20170223
// @grant none
// ==/UserScript==
var checkLoadInterval;
function generateHistoryButton(target) {
var historyButton = document.createElement('button');
historyButton.className = 'full-width onboarded button-icon-left';
historyButton.style = 'background-color: rgb(71, 119, 180); margin: -5% 0;';
historyButton.setAttribute('data-uri','label/feedly.history');
historyButton.innerText = 'Recently Read';
target.parentNode.appendChild(historyButton);
}
function checkLoaded() {
var targetButton = document.getElementById('addContentPlaceholderFX');
if (targetButton) {
window.clearInterval(checkLoadInterval);
targetButton = targetButton.querySelector('button');
targetButton.style.padding = '1px';
targetButton.style.margin = '-3% 0';
generateHistoryButton(targetButton);
}
}
checkLoadInterval = setInterval(checkLoaded, 5000);
// ==UserScript==
// @name 翠穗書架 Mod
// @namespace https://gist.github.com/colt365/
// @description Modifying s-bookshelf.blog.jp for DTA.
// @include /^https?://s-bookshelf\.blog\.jp/.*$/
// @version 1.1.20180717
// @grant none
// ==/UserScript==
[...document.querySelectorAll('div.article-body-inner a')].forEach(a=>{
let t = document.createElement('div');
let img = a.children[0];
if (img) {
t.innerText = img.alt;
img.alt = '';
} else {
t.innerText = a.title;
}
t.className = 'description';
a.append(t);
a.title = '';
});
var sheet = (function() {
var style = document.createElement("style");
// style.setAttribute("media", "screen")
style.appendChild(document.createTextNode("")); // For WebKit
document.head.appendChild(style);
return style.sheet;
})();
sheet.insertRule("div.description::before{content: '↑ '!important;}");
@JiaqiTu
Copy link
Copy Markdown

JiaqiTu commented Nov 14, 2023

下载的title解码是乱码,没加utf-8? eg:(title: "ã€�全文已完结】女å�‹è¢«è¿žçޝæ�€äººçНè™�æ�€åœ¨æˆ‘们的婚房中。一年å�Žï¼Œä¸€ä¸ªå¥³å­©å�‘我告白。我刚è¦�æ‹’ç»�,å�´å�¬åˆ°äº†å¥³å­©çš„心声。ã€�这男主好难攻略啊,还好...",)

@JiaqiTu
Copy link
Copy Markdown

JiaqiTu commented Nov 14, 2023

没问题了,using json format打开了,哈哈

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment