Melonbooks: cart: save to file

Save cart to text file

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==UserScript==
// @name         Melonbooks: cart: save to file
// @namespace    http://darkfader.net/
// @version      0.1
// @run-at       document-idle
// @description  Save cart to text file
// @author       Rafael Vuijk
// @match        http*://www.melonbooks.co.jp/clipboard/*
// @require      http://code.jquery.com/jquery.min.js
// @grant        GM_openInTab
// @grant        GM_registerMenuCommand
// @grant        GM_download
// ==/UserScript==

(function() {
    'use strict';

    function save_cart() {
        //var file = new File(["Hello, world!"], "melonbooks_cart.txt", {type: "text/plain;charset=utf-8"});
        //saveAs(file);//blob, "cart.txt");

        let str = '';

        $("table[class='list mb20']").find("tr").each(function () {
            str += $(this).find("td[class='name']").find("a").text() + '\n';
        });

        // let test = 'data:text/plain;charset=utf-8;base64,' + btoa(str));
        let test = 'data:text/plain;charset=utf-8,' + encodeURIComponent(str);

        GM_download({
            url: test,
            name: "melonbooks_cart.txt",
            headers: {}, // - see GM_xmlhttpRequest for more details
            saveAs: false, // - boolean value, show a saveAs dialog
            onerror: () => { console.log('error'); },
            onload: () => { console.log('finished'); },
            onprogress: () => { console.log('progress'); },
            ontimeout: () => { console.log('timeout'); },
        });
    }

    GM_registerMenuCommand("save cart (delete first!)", save_cart, "s");

//    save_cart();

    console.log('---------------------');

    $("table[class='list mb20']").find("tr").each(function () {
        var title = $(this).find("td[class='name']").find("a").text();
        title = title.replace(/【メロン.*】/, "");
        console.log(title);
        let link = function() {
            var td = $('<td/>');
            // insertAfter, wrap etc..
            var link = $('<a/>');
            link.attr('target', '_blank');
            link.attr('href', 'https://www.suruga-ya.jp/search?searchbox=1&category=11&search_word=' + title);
            link.text('suru');
            td.append(link);
            return td;
        };
        let img = $(this).find("td[class='img']");
        link().insertAfter(img);
    });

})();