京东JD无货商品加购物车

修改按钮和链接,使京东JD无货商品可加入购物车,方便购买

// ==UserScript==
// @name         京东JD无货商品加购物车
// @namespace    https://mou.science
// @version      0.1
// @description  修改按钮和链接,使京东JD无货商品可加入购物车,方便购买
// @author       You
// @match        https://item.jd.com/*
// @grant        none
// ==/UserScript==
function editButton(){
    let item_id = window.location.href.match(/.*\/(\d+).html.*?/)[1];
    let cartButton = document.getElementById('InitCartUrl');
    if (cartButton.href.indexOf("#none") != -1 ){
        cartButton.href = 'http://gate.jd.com/InitCart.aspx?pid='+item_id + '&pcount=1&ptype=1'
        cartButton.setAttribute("class",'btn-special1 btn-lg');
    }
}

(function() {
    'use strict';
    window.addEventListener('load', function() {
        editButton();
    }, false);
})();