Greasy Fork

Greasy Fork is available in English.

Get sgf files

Retrieve all sgf files!

当前为 2021-02-10 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Get sgf files
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Retrieve all sgf files!
// @author       Qiang Li
// @match        http://sinago.com/gibo/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    console.log('i am running');

    //
    var hrefs = new Array();
    var els = document.querySelectorAll(' a[href*="sgf"]')
    var elsarray = [...els]
    let title1;
    let title2;
    let title3;
    var elsarray2 = [];
    elsarray.forEach((xx, index) => {
        // get the url
        let s = xx.href.indexOf("http");
        let e = xx.href.indexOf("sgf");
        let yy = xx.href.substring(s, e + 3);
        // get the text

        if (index % 3 === 0){
            title1 = xx.innerText;
        }else if (index % 3 === 1){
            title2 = xx.innerText;
        }else {

            title3 = xx.innerText;
            //console.log('title1 ' + title1+',title2 '+title2 +', title3 '+title3 )
            // we can create object {title, url}
            elsarray2.push({name: `${title1}-${title2}-${title3}.sgf`,url:yy});
        }
    });
    //console.log(elsarray2);
    // fetch the first one
    async function fetchsgf(url) {
        const res = await fetch(url);
        const sgf = await res.text();
        return sgf;
    }
    function download(content, fileName, contentType) {
        console.log(fileName);
        var a = document.createElement("a");
        var file = new Blob([content], {type: contentType});
        a.href = URL.createObjectURL(file);
        a.download = fileName;
        a.click();
    }

    function downloadAll(){
        console.log("downloadall");
        //
        elsarray2.forEach(o => {
            fetch(o.url)
                  .then(response => response.text())
                  .then(data => download(data, o.name, 'text/plain'));
        });
    }
    AddYT();
    //download(jsonData, 'json.txt', 'text/plain');
    //fetch(elsarray2[0].url)
    //    .then(response => response.text())
    //    .then(data => download(data, elsarray2[0].name, 'text/plain'));

    function AddYT() {
    var buttonDiv = document.createElement("td");
    buttonDiv.id = "punisher";
    buttonDiv.style.width = "80";
    var addButton = document.createElement("a");
    addButton.appendChild(document.createTextNode("下载棋谱"));
    addButton.style.width = "100%";
    addButton.style.cursor = "pointer";
    addButton.style.height = "inherit";
     addButton.style.backgroundColor ="red";
     addButton.style.color = "white";

    addButton.style.border = "0";
    addButton.style.borderRadius = "2px";
    addButton.style.fontSize = "1rem";
    addButton.style.fontFamily = "inherit";
    addButton.style.textAlign = "center";
    addButton.style.textDecoration = "none";
    addButton.onclick = downloadAll;
    buttonDiv.appendChild(addButton);
    var targetElement = document.querySelectorAll("select");
    var tp = targetElement[0].parentNode.parentNode;

    tp.appendChild(buttonDiv);

}
})();