京东无货商品加购物车

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

// ==UserScript==
// @name         京东无货商品加购物车
// @namespace    https://greasyfork.org/zh-CN/scripts/441968
// @version      0.2
// @description  修改按钮和链接,使京东JD无货商品可加入购物车,方便购买
// @author       You
// @match        https://item.jd.com/*
// @grant        none
// @license MIT
// ==/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.href = 'https://cart.jd.com/gate.action?pid=' + item_id + '&pcount=1&ptype=1'
        cartButton.setAttribute("class",'btn-special1 btn-lg');
    }
}
 
(function() {
    'use strict';
    window.addEventListener('load', function() {
        editButton();
    }, false);
})();