// ==UserScript==
// @name moegirlTable
// @namespace http://tampermonkey.net/
// @version 1.04
// @description 萌娘百科新番列表產生Table
// @author backrock12
// @match https://zh.moegirl.org.cn/*
// @require http://libs.baidu.com/jquery/2.0.0/jquery.min.js
// @require https://cdn.bootcdn.net/ajax/libs/FileSaver.js/2.0.5/FileSaver.min.js
// @grant none
// @downloadURL none
// ==/UserScript==
(function () {
'use strict';
var $ = $ || window.$;
var table;
async function getBase64(imgUrl) {
return new Promise((resolve, reject) => {
window.URL = window.URL || window.webkitURL;
var xhr = new XMLHttpRequest();
xhr.open("get", imgUrl, true);
xhr.responseType = "blob";
xhr.onload = function () {
if (this.status == 200) {
//得到一个blob对象
var blob = this.response;
// 至关重要
let oFileReader = new FileReader();
oFileReader.onloadend = function (e) {
// 此处拿到的已经是base64的图片了,可以赋值做相应的处理
resolve(e.target.result)
}
oFileReader.readAsDataURL(blob);
}
console.log('imgUrl', this.status)
}
xhr.send();
});
}
async function createtable() {
var listc = [];
var num = 1;
var tcaption = $('h1').eq(0).text();
var lista = $('h2');
lista.each(function () {
var t = $(this);
var name = t.text();
if (name != '目录' && name != '导航' && name != '参见' && name != '导航菜单' &&
name != '注释' && name != '公告' && name != '讨论中事项' && name != '投票中事项'
&& name != "关于萌娘百科站内广告的说明" && name != "已结束投票"
) {
var href = t.nextAll('.thumb').find('img').eq(0).attr('src');
var time = t.nextAll('dl').find('dd').eq(1).text();
var type = t.nextAll('ul').find('li').eq(0);
var describe = t.nextAll('.poem').eq(0);
var staff = t.nextAll('.columns-list').eq(0);
var cast = t.nextAll('.columns-list').eq(1);
var expect = '';
var feedback = '';
describe = describe.length > 0 ? describe.html().replace(/[\n\r]/g, '') : '';
staff = staff.length > 0 ? staff.html().replace(/[\n\r]/g, '') : '';
cast = cast.length > 0 ? cast.html().replace(/[\n\r]/g, '') : '';
time = time.replace('起', '起
').replace(/[\n\r]/g, '');
type = type.length > 0 ? type.text().replace(/[\n\r]/g, '') : '';
type = type == '点此进入官方网站' ? '' : type.replace(/[\n\r]/g, '');
var c = { no: num++, name: name, href: href, describe: describe, time: time, staff: staff, cast: cast, type: type, expect: expect, feedback: feedback }
listc.push(c);
}
});
let mdtable = '';
table = $('