// ==UserScript== // @name moegirlTable // @namespace http://tampermonkey.net/ // @version 1.02 // @description 萌娘百科新番列表產生Table // @author backrock12 // @match https://zh.moegirl.org/* // @require http://libs.baidu.com/jquery/2.0.0/jquery.min.js // @grant none // @downloadURL none // ==/UserScript== (function ( ) { 'use strict'; var $ = $ || window.$; var table; 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 != '导航菜单') { 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() : ''; staff = staff.length > 0 ? staff.html() : ''; cast = cast.length > 0 ? cast.html() : ''; time = time.replace('起', '起
'); type = type.length > 0 ? type.text() : ''; type = type == '点此进入官方网站' ? '' : type; 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); } }); table = $('
'); var th = '' + tcaption + ''; th += ''; th += '序号'; th += '名称'; th += '封面'; th += '播出时间'; th += '简介'; th += 'STAFF'; th += 'CAST'; th += '类型'; th += '期望'; th += '观后感'; th += ''; table.append(th); listc.forEach(function (t) { var tr = ''; tr += '' + t.no + ''; tr += '' + t.name + ''; tr += ''; tr += '' + t.time + ''; tr += '' + t.describe + ''; tr += '' + t.staff + ''; tr += '' + t.cast + ''; tr += '' + t.type + ''; tr += '' + t.expect + ''; tr += '' + t.feedback + ''; tr += ''; table.append(tr); }); //$('body').append(table); console.log(listc); console.log(table); } function inits() { var content = document.createElement("div"); document.body.appendChild(content); content.outerHTML = `
产生TABLE
`; var WCSave = document.querySelector("#CWDownSave"); WCSave.onclick = function () { createtable(); var newwindow = window.open('', "_blank", ''); var html = '' + table.html() + '
'; newwindow.document.write(html); } } inits(); })( );