// ==UserScript== // @name amzOrderHistoryFilter // @name:ja アマゾン注文履歴フィルタ // @namespace http://furyu.hatenablog.com/ // @author furyu // @version 0.1.0.23 // @include https://www.amazon.co.jp/gp/your-account/order-history* // @include https://www.amazon.co.jp/gp/css/order-history* // @include https://www.amazon.co.jp/gp/digital/your-account/order-summary.html* // @include https://www.amazon.co.jp/gp/css/summary/print.html* // @include https://www.amazon.co.jp/ap/signin* // @require https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js // @require https://greasyfork.org/scripts/398566-concurrent-promise/code/concurrent_promise.js?version=784632 // @grant GM_setValue // @grant GM_getValue // @description You will be able to view your Amazon (amazon.co.jp) order history by month, and view and print receipts by month or year at a time. // @description:ja アマゾン(amazon.co.jp)の注文履歴を月別表示したり、月別もしくは通年の領収書をまとめて表示・印刷したりできるようになります。 // @license MIT // @compatible chrome // @compatible firefox // @supportURL https://github.com/furyutei/amzOrderHistoryFilter/issues // @contributionURL https://memo.furyutei.work/about#%E6%B0%97%E3%81%AB%E5%85%A5%E3%81%A3%E3%81%9F%E5%BD%B9%E3%81%AB%E7%AB%8B%E3%81%A3%E3%81%9F%E3%81%AE%E3%81%8A%E6%B0%97%E6%8C%81%E3%81%A1%E3%81%AF%E3%82%AE%E3%83%95%E3%83%88%E5%88%B8%E3%81%A7 // @downloadURL none // ==/UserScript== /* ■ 外部ライブラリ - [jQuery](https://jquery.com/) The MIT License [License | jQuery Foundation](https://jquery.org/license/) ■ 関連記事など - [【アマゾン注文履歴フィルタ】Kindle 等のデジタルコンテンツの領収書をまとめて表示する拡張機能/アドオン/ユーザースクリプト](http://furyu.hatenablog.com/entry/amzOrderHistoryFilter) - [furyutei/amzOrderHistoryFilter](https://github.com/furyutei/amzOrderHistoryFilter) */ /* The MIT License (MIT) Copyright (c) 2018 furyu Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ ( function () { 'use strict'; // ■ パラメータ { var OPTIONS = { OPEN_PRINT_DIALOG_AUTO : false, // true: 印刷ダイアログを自動で起動 REMOVE_REISSUE_STRINGS : false, // true: 「再発行」を取り除く ADDRESSEE_CHANGEABLE : true, // true: 宛名を設定・変更可 ENABLE_PRINT_PREVIEW_BUTTON : true, // true: 印刷プレビューボタンを表示(Firefox用) DEFAULT_FILTER_INCLUDE_DIGITAL : true, // フィルタ対象(デジタルコンテンツ)のデフォルト値(true: 有効) DEFAULT_FILTER_INCLUDE_NONDIGITAL : false, // フィルタ対象(デジタルコンテンツ以外)のデフォルト値(true: 有効) DEFAULT_FILTER_INCLUDE_RESERVATION : true, // フィルタ対象(予約)のデフォルト値(true: 有効) DEFAULT_FILTER_INCLUDE_PRICE_ZERO : true, // フィルタ対象(合計¥0)のデフォルト値(true: 有効) OPERATION : true // true: 動作中、false: 停止中 }; // } // ■ 共通変数 { var SCRIPT_NAME = 'amzOrderHistoryFilter', DEBUG = false; if ( typeof jQuery != 'function' ) { console.error( SCRIPT_NAME + ':', 'Library not found - ', 'jQuery:', typeof jQuery ); return; } var $ = jQuery, IS_WEB_EXTENSION = !! ( window.is_web_extension ), IS_FIREFOX = ( 0 <= navigator.userAgent.toLowerCase().indexOf( 'firefox' ) ), IS_EDGE = ( 0 <= navigator.userAgent.toLowerCase().indexOf( 'edge' ) ), WEB_EXTENSION_INIT = window.web_extension_init, ORDER_HISTORY_FILTER = null, DEFAULT_OPTIONS = {}, IS_TOUCHED = ( function () { var touched_id = SCRIPT_NAME + '_touched', jq_touched = $( '#' + touched_id ); if ( 0 < jq_touched.length ) { return true; } $( '' ).attr( 'id', touched_id ).css( 'display', 'none' ).appendTo( $( document.documentElement ) ); return false; } )(); if ( IS_TOUCHED ) { console.error( SCRIPT_NAME + ': Already loaded.' ); return; } OPTIONS.SELECT_MONTH_LABEL_TEXT = '対象月選択'; OPTIONS.SELECT_MONTH_NO_SELECT_TEXT = '未選択'; OPTIONS.SELECT_MONTH_ALL_TEXT = '全て'; OPTIONS.CHECKBOX_FILTER_INCLUDE_DIGITAL_TEXT = 'デジタル'; OPTIONS.CHECKBOX_FILTER_INCLUDE_NONDIGITAL_TEXT = 'デジタル以外'; OPTIONS.CHECKBOX_FILTER_INCLUDE_RESERVATION_TEXT = '予約分を含む'; OPTIONS.CHECKBOX_FILTER_INCLUDE_PRICE_ZERO = '合計¥0の注文を含む'; OPTIONS.COUNTER_LABEL_DIGITAL_TEXT = 'デジタル'; OPTIONS.COUNTER_LABEL_NONDIGITAL_TEXT = 'デジタル以外'; OPTIONS.SELECT_DESTINATION_LABEL_TEXT = 'お届け先'; OPTIONS.SELECT_DESTINATION_ALL_TEXT = '全て'; OPTIONS.SELECT_DESTINATION_NON_TEXT = '宛先無し'; // TODO: 宛先無しのときに適切なキーがわからないため保留(住所の氏名欄は割と何でも受け付けてしまうため、被らないのが思いつかない) OPTIONS.PRINT_RECEIPT_BUTTON_TEXT = '領収書印刷用画面'; OPTIONS.LOGIN_REQUIRED_MESSAGE = 'サーバーよりログインを要求されたため、取得を中止しました。リロードしますか?'; OPTIONS.RECEIPT_READ_TIMEOUT_MESSAGE = '応答がないままタイムアウトしたものがありました。領収書の取得を最初からやり直しますか?'; OPTIONS.CSV_DOWNLOAD_BUTTON_TEXT = '注文履歴CSV(参考用)ダウンロード'; OPTIONS.REFUND_CSV_DOWNLOAD_BUTTON_TEXT = '返金情報CSV(参考用)ダウンロード'; OPTIONS.CHANGE_ADDRESSEE_BUTTON_TEXT = '宛名変更'; OPTIONS.CHANGE_ADDRESSEE_PROMPT_MESSAGE = '宛名を指定してください'; OPTIONS.PRINT_PREVIEW_BUTTON_TEXT = '印刷プレビュー'; OPTIONS.TEXT_FILTER_LABEL_TEXT = '絞り込み'; OPTIONS.TEXT_FILTER_PLACEHOLDER_TEXT = 'キーワード、または、注文番号を入力'; OPTIONS.TEXT_FILTER_HELP_TEXT = '" "(スペース)区切→AND検索、" OR "区切→OR検索'; OPTIONS.TEXT_FILTER_KEYWORDS_RULED_OUT_CHECKBOX_LABEL_TEXT = '除外'; OPTIONS.TEXT_FILTER_APPLY_BUTTUON_TEXT = '適用'; OPTIONS.TEXT_FILTER_CLEAR_BUTTUON_TEXT = 'クリア'; // } // ■ 関数 { function to_array( array_like_object ) { return Array.prototype.slice.call( array_like_object ); } // end of to_array() if ( typeof console.log.apply == 'undefined' ) { // MS-Edge 拡張機能では console.log.apply 等が undefined // → apply できるようにパッチをあてる // ※参考:[javascript - console.log.apply not working in IE9 - Stack Overflow](https://stackoverflow.com/questions/5538972/console-log-apply-not-working-in-ie9) [ 'log', 'info', 'warn', 'error', 'assert', 'dir', 'clear', 'profile', 'profileEnd' ].forEach( function ( method ) { console[ method ] = this.bind( console[ method ], console ); }, Function.prototype.call ); console.log( 'note: console.log.apply is undefined => patched' ); } function log_debug() { if ( ! DEBUG ) { return; } var arg_list = [ '[' + SCRIPT_NAME + ']', '(' + ( new Date().toISOString() ) + ')' ]; console.log.apply( console, arg_list.concat( to_array( arguments ) ) ); } // end of log_debug() function log_info() { var arg_list = [ '[' + SCRIPT_NAME + ']', '(' + ( new Date().toISOString() ) + ')' ]; console.info.apply( console, arg_list.concat( to_array( arguments ) ) ); } // end of log_error() function log_error() { var arg_list = [ '[' + SCRIPT_NAME + ']', '(' + ( new Date().toISOString() ) + ')' ]; console.error.apply( console, arg_list.concat( to_array( arguments ) ) ); } // end of log_error() var set_value = ( function () { if ( typeof GM_setValue != 'undefined' ) { return function ( name, value ) { return GM_setValue( name, value ); }; } return function ( name, value ) { return localStorage.setItem( name, value ); }; } )(); // end of set_value() var get_value = ( function () { if ( typeof GM_getValue != 'undefined' ) { return function ( name ) { var value = GM_getValue( name ); // メモ: 値が存在しない場合、GM_getValue( name ) は undefined を返す return ( value === undefined ) ? null : value; }; } return function ( name ) { // メモ: 値が存在しない場合、localStorage[ name ] は undefined を、localStorage.getItem( name ) は null を返す return localStorage.getItem( name ); }; } )(); // end of get_value() function zen_to_han( source_string ) { return source_string .replace( /[A-Za-z0-9]/g, function( match_string ) { return String.fromCharCode( match_string.charCodeAt( 0 ) - 0xFEE0 ); } ) .replace( /[\u3000]/g, ' ' ); } // end of zen_to_han() function get_safefilename( source_filename ) { return source_filename.replace( /[\\\/:*?"<>|;]/g, '_' ); } // end of get_safefilename() var object_extender = ( function () { // 参考: [newを封印して、JavaScriptでオブジェクト指向する(1): Architect Note](http://blog.tojiru.net/article/199670885.html?seesaa_related=related_article) function object_extender( base_object ) { var template = object_extender.template, mixin_object_list = Array.prototype.slice.call( arguments, 1 ), expanded_object; template.prototype = base_object; expanded_object = new template(); mixin_object_list.forEach( function ( object ) { Object.keys( object ).forEach( function ( name ) { expanded_object[ name ] = object[ name ]; } ); } ); return expanded_object; } // end of object_extender() object_extender.template = function () {}; return object_extender; } )(); // end of object_extender() function get_origin_url( url ) { if ( ! url ) { url = window.location.href; } try { return url.match(/^[^:]+:\/{2}[^/]+/)[ 0 ]; } catch ( error ) { return url; } } // end of get_origin_url() function get_absolute_url( path, base_url ) { if ( ! base_url ) { base_url = window.location.href; } try { return new URL( path, base_url ).href; } catch ( error ) { return path; } } // end of get_absolute_url() var { open_child_window, get_child_window_iframe, remove_child_window_iframe, } = ( () => { var child_window_counter = 0, jq_iframe_template = $( '