TabacooRecorder

Record your tabacoo order

当前为 2016-12-14 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         TabacooRecorder
// @namespace    https://greasyfork.org/users/86741
// @author       huage
// @description  Record your tabacoo order
// @include      http://gdgz.xinshangmeng.com*
// @grant        GM_registerMenuCommand
// @grant        GM_getValue
// @grant        GM_setValue
// @version      0.1
// @run-at       document-end
// @license      MIT
// ==/UserScript==

/****************************************
######## version 20161214 #########
保存在新商盟的最近一次下单记录
****************************************/
console.log("华哥的记录保存脚本开始执行!");

//注册菜单
GM_registerMenuCommand('保存输入',Save);
GM_registerMenuCommand('读取记录',Load);
GM_registerMenuCommand('控制台显示记录',ShowInConsole);
console.log('脚本菜单注册成功');

//全局变量,常量
var recordJson={}; //记录json
var _lastRecord='lastRecord'; //记录最后一次输入的数据名,_开头表示常量

//保存输入
function Save(){
  console.log('开始保存输入');
  for(var i=1;i<1024;i++){
    id='sort_'+i;
    li=document.getElementById(id);
    if(!li){
      break;
    }
    num=li.getElementsByTagName('input')[1].value;
    if(num>0){
      recordJson[id]=num;
    }
  }
  newRecord=JSON.stringify(recordJson);
  GM_setValue(_lastRecord,newRecord);
  console.log('保存输入成功!保存的json是:');
  console.log(newRecord);
}

//读取输入
function Load(){
  alert('注意!读取记录基于上次的网页编排\n,如编排被改变可能引发错误,请仔细核对!');
  console.log('开始读取输入');
  record=JSON.parse(GM_getValue(_lastRecord));
  console.log(record);
  for(var id in record){
    li=document.getElementById(id);
    li.getElementsByTagName('input')[1].value=record[id];
  }
  console.log('读取输入成功');
}

//控制台查看保存记录
function ShowInConsole(){
  console.log('控制台显示保存记录:');
  record=GM_getValue(_lastRecord);
  console.log(record);
}