// ==UserScript==
// @name [Neko0] 淘宝天猫一键好评
// @description 淘宝&天猫评价页面添加一键好评按钮
// @version 1.7.1
// @author JoJunIori
// @namespace neko0-web-tools
// @icon https://www.taobao.com/favicon.ico
// @homepageURL https://github.com/nekozero/neko0-web-tools
// @supportURL https://github.com/nekozero/neko0-web-tools/issues
// @grant GM_addStyle
// @grant GM_setValue
// @grant GM_getValue
// @run-at document-idle
// @license AGPLv3
// @require https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.8.1/js/solid.min.js
// @require https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.8.1/js/fontawesome.min.js
// @require https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.11/lodash.min.js
// @require https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.0/jquery.min.js
// @include *://rate.taobao.com/*
// @include *://ratewrite.tmall.com/*
// @include *://buyertrade.taobao.com/trade*
// @downloadURL none
// ==/UserScript==
// 初始化设定
var taobaorate = {
autorate: false,
rateMsgListText:
'很满意的一次购物。真的很喜欢。完全超出期望值。质量非常好。掌柜好人,一生平安。非常满意。与卖家描述的完全一致。发货速度非常快。包装非常仔细、严实。物流公司服务态度很好。运送速度很快。下次有需求还来买。服务周到,态度热情。发货及时,物流很快。各方面都满意。给你全五星好评。',
autoSort: true,
autoDel: 3,
}
if (GM_getValue('taobaorate') === undefined) {
GM_setValue('taobaorate', taobaorate)
}
// Math.floor(Math.random()*10);
// 置入Style
GM_addStyle(`
/* 设置框 */
.n-box {
user-select: none;
position: fixed;
right: 40px;
bottom: 80px;
width: 56px;
height: 56px;
padding: 12px;
background: white;
border-radius: 3px;
box-sizing: border-box;
z-index: 99999;
color: #888;
border: 2px solid #f5f5f5;
transition: all 256ms;
z-index: 1000000;
overflow: hidden;
}
.n-box.open {
width: 296px;
height: 266px;
}
.n-box > *:not(.switch){
opacity: 0;
transition: all 256ms;
}
.n-box.open > *:not(.switch){
opacity: 1;
}
/* 开关按钮 */
.n-box .button.switch {
position: absolute;
right: 0;
bottom: 0;
width: 56px;
height: 56px;
display: flex;
align-items: center;
justify-content: center;
transition: all 256ms;
z-index: 1;
}
.n-box.open .button.switch {
transform: rotate(180deg);
}
/* 其他 */
.n-box label {
display: block;
}
.n-box label .word-count {
float: right;
}
/* 输入框 */
.n-box textarea {
display: block;
width: 100%;
padding: 6px;
box-sizing: border-box;
margin-top: 6px;
}
/* 更新按钮 */
.n-box .button.update {
display: block;
width: 100%;
padding: 6px 12px;
margin-top: 6px;
box-sizing: border-box;
text-align: center;
background: #ff4401;
color: white;
border-radius: 3px;
cursor: pointer;
}
/* 开关 */
.n-box .toggle {
float: left;
padding: 6px;
box-sizing: border-box;
margin-top: 6px;
}
.n-box .toggle.auto-sort > span{
display: none;
}
/* 输入框 */
.n-box .input.auto-del {
float: left;
margin-top: 6px;
}
.n-box .input.auto-del input {
border: none;
box-sizing: border-box;
padding: 6px;
width: 30px;
text-align: center;
float: left;
box-shadow: inset 0 0 0 1px #888888;
border-radius: 6px;
}
.n-box .input.auto-del label {
float: left;
padding: 6px;
}
/* 一键评价 */
.submitbox {
text-align: center;
padding: 20px 0 6px !important;
}
.submitboxplus {
user-select: none;
text-align: center;
}
.tb-btn {
color: #fff;
background-color: #3498db;
box-shadow: inset 0 -2px 0 rgba(0,0,0,.15);
display: inline-block;
text-decoration: none;
text-align: center;
font-size: 13px;
line-height: 1.385;
padding: 9px 13px;
border-radius: 4px;
border: none;
font-weight: 400;
transition: color .25s linear,background-color .25s linear;
cursor: pointer;
}
.tb-btn:hover {
background-color: #5dade2;
border-color: #5dade2;
}
.tb-btn.haoping {
background-color: #f40;
border-color: #f40;
}
.tm-btn {
user-select: none;
display: inline-block;
padding: 0 10px;
border: 0;
line-height: 25px;
font-weight: 700;
background: 0 0;
cursor: pointer;
text-align: center;
margin: 0 6px 12px;
border-radius: 2px;
color: #c40000;
background-color: #fff;
box-shadow: inset 0 0 0 1px;
}
.tm-btn.haoping {
user-select: none;
color: #fff;
background-color: #c40000;
box-shadow: none;
}
.list-auto-btn {
margin-top: 10px;
background-color: #fff;
border: 1px solid #dcdcdc;
color: #3c3c3c;
height: 28px;
line-height: 26px;
padding: 0 12px;
border-radius: 3px;
font-size: 12px;
cursor: pointer;
display: inline-block;
}
.list-auto-btn:hover {
border-color: #ff1d00;
color: #ff1d00;
}
`)
// 置入DOM
let dom = `
`
$('body').append(dom)
// 绑定点击事件
// 打开设置窗口
$('.n-box .button.switch').click(() => {
$('.n-box').toggleClass('open')
})
// 提交评语更新
$('.n-box .button.update.rate-msg-list-text').click(() => {
let store = GM_getValue('taobaorate')
store.rateMsgListText = $('#rateMsgListText').val()
GM_setValue('taobaorate', store)
})
// 切换自动打乱排序
$('.n-box .toggle.auto-sort').click(() => {
$('.auto-sort .on').toggle()
$('.auto-sort .off').toggle()
let store = GM_getValue('taobaorate')
store.autoSort = !store.autoSort
GM_setValue('taobaorate', store)
})
// 监听字数
$('.word-count').text($('#rateMsgListText').val().length)
$('#rateMsgListText').bind('input propertychange', function () {
$('.word-count').text($(this).val().length)
})
// 监听删除数
$('#autoDel').bind('input propertychange', function () {
let store = GM_getValue('taobaorate')
store.autoDel = $(this).val()
GM_setValue('taobaorate', store)
})
// 写入已存储的设置
$('#rateMsgListText').val(GM_getValue('taobaorate').rateMsgListText)
$('#autoDel').val(JSON.parse(GM_getValue('taobaorate').autoDel))
if (JSON.parse(GM_getValue('taobaorate').autoSort)) {
$('.auto-sort .on').show()
$('.auto-sort .off').hide()
} else {
$('.auto-sort .off').show()
$('.auto-sort .on').hide()
}
/**
* 数组随机排序并抽取指定数量
*
* @param {array} arr 要进行处理的数组
* @param {string} count 最终输出结果的个数
*
* @return {array} 输出处理后的数组
*/
function getRandomArrayElements(arr, count) {
var shuffled = arr.slice(0),
i = arr.length,
min = i - count,
temp,
index
while (i-- > min) {
index = Math.floor((i + 1) * Math.random())
temp = shuffled[index]
shuffled[index] = shuffled[i]
shuffled[i] = temp
}
return shuffled.slice(min)
}
/**
* 对评语进行处理
*
* @return {string} 返回处理过的评语内容
*/
function processedText() {
var text = GM_getValue('taobaorate').rateMsgListText
console.log(text)
var autoDel = JSON.parse(GM_getValue('taobaorate').autoDel)
// 随机排序评语
if (JSON.parse(GM_getValue('taobaorate').autoSort)) {
var arr = text.split('。')
var count = autoDel ? arr.length - autoDel : arr.length // 随机删除评语个数设定
text = getRandomArrayElements(arr, count).join(' ')
}
return text
}
var host = window.location.host
var isTB = host === 'rate.taobao.com'
var isTM = host === 'ratewrite.tmall.com'
var isList = host === 'buyertrade.taobao.com'
// 淘宝一键好评
function taobaoStar() {
var tbGoodRate = document.querySelectorAll('.good-rate')
for (var i = 0, a; (a = tbGoodRate[i++]); ) {
a.click()
}
var tbStar = document.querySelectorAll('.rate-stars label')
tbStar[4].childNodes[0].click()
tbStar[9].childNodes[0].click()
tbStar[14].childNodes[0].click()
}
function taobaoMsg() {
var tbRateMsg = document.querySelectorAll('.rate-msg')
for (var i = 0, a; (a = tbRateMsg[i++]); ) {
// 写入评价
a.value = processedText()
}
}
function taobaoFun() {
let elemStar = ``
$('.submitbox').after(elemStar)
$('.tb-btn.star').click(() => {
taobaoStar()
})
$('.tb-btn.msg').click(() => {
taobaoMsg()
})
$('.tb-btn.starmsg').click(() => {
taobaoMsg()
taobaoStar()
})
$('.tb-btn.haoping').click(() => {
taobaoMsg()
taobaoStar()
setTimeout(() => {
$('.J_submit_rate').click()
}, 500)
})
}
// 天猫一键好评
function tmallStar() {
var tmStar = document.querySelectorAll('[data-star-value="5"]')
for (var i = 0, a; (a = tmStar[i++]); ) {
a.click()
}
}
function tmallMsg() {
// 写入评价
let textInputer
if (document.querySelector('.J_textInput')) textInputer = document.querySelectorAll('.J_textInput')
if (document.querySelector('.J_textEditorContent')) textInputer = document.querySelectorAll('.J_textEditorContent')
if (document.querySelector('.J_textInput').shadowRoot) {
if (document.querySelector('.J_textInput').shadowRoot.querySelector('#textEditor').shadowRoot) {
textInputer = document
.querySelector('.J_textInput')
.shadowRoot.querySelector('#textEditor')
.shadowRoot.querySelectorAll('#textEl')
}
}
for (var i = 0, a; (a = textInputer[i++]); ) {
a.value = processedText()
}
}
function tmallFun() {
let elemStar = ``
$('.compose-submit').after(elemStar)
$('.tm-btn.star').click(() => {
tmallStar()
})
$('.tm-btn.msg').click(() => {
tmallMsg()
})
$('.tm-btn.starmsg').click(() => {
tmallMsg()
tmallStar()
})
$('.tm-btn.haoping').click(() => {
tmallMsg()
tmallStar()
setTimeout(() => {
$('.compose-btn [type="submit"]').click()
}, 500)
})
}
// 自动执行Function
let autorate = () => {
// 判断开启才执行
if (GM_getValue('taobaorate').autorate) {
setTimeout(function () {
$('.submitboxplus .haoping')[0].click()
// 关闭自动执行开关
let store = GM_getValue('taobaorate')
store.autorate = false
GM_setValue('taobaorate', store)
}, 2000)
setTimeout(() => {
open(location, '_self').close()
}, 4000)
}
}
function test(i) {}
// 判断页面后添加对应页面元素
if (isList) {
$("a[class^='button-']:contains('评价')").each(function () {
let dom = `一键好评`
$(this).parent().append(dom)
// console.log($(this).attr('href'))
})
$("a:contains('一键好评')").each(function () {
$(this).click(function () {
// 打开自动执行开关
let store = GM_getValue('taobaorate')
store.autorate = true
GM_setValue('taobaorate', store)
// 跳转页面
setTimeout(() => {
window.open($(this).prev().attr('href'), '_blank')
}, 300)
})
})
} else if (isTB) {
taobaoFun()
autorate()
} else if (isTM) {
var timer = setInterval(detection, 1000)
detection()
}
function detection() {
var haoping = document.querySelector('.haoping')
if (!haoping) {
tmallFun()
autorate()
} else {
clearInterval(timer)
}
}