Last active
September 9, 2021 09:52
-
-
Save longnull/d1be9d83021acef5abdbe36819c7fc53 to your computer and use it in GitHub Desktop.
AliExpress Seller Reviews From Miped
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name AliExpress Seller Reviews From Miped | |
// @description Отображает негативные отзывы о продавцах опубликованные на форуме Miped | |
// @author longnull | |
// @namespace longnull | |
// @version 1.0.2 | |
// @updateURL https://gist.github.com/longnull/d1be9d83021acef5abdbe36819c7fc53/raw/AliExpressSellerReviewsFromMiped.user.js | |
// @downloadURL https://gist.github.com/longnull/d1be9d83021acef5abdbe36819c7fc53/raw/AliExpressSellerReviewsFromMiped.user.js | |
// @match *://*.aliexpress.com/item/* | |
// @match *://*.aliexpress.com/i/* | |
// @match *://*.aliexpress.com/store/* | |
// @match *://*.aliexpress.ru/item/* | |
// @match *://*.aliexpress.ru/i/* | |
// @match *://*.aliexpress.ru/store/* | |
// @exclude *://m.aliexpress.com/* | |
// @exclude *://m.aliexpress.ru/* | |
// @grant GM_xmlhttpRequest | |
// @grant GM.xmlHttpRequest | |
// @connect 45.132.104.115 | |
// @noframes | |
// ==/UserScript== | |
(async () => { | |
'use strict'; | |
//========================================================================================= | |
const config = { | |
// Ширина панели | |
panelWidth: '400px' | |
}; | |
//========================================================================================= | |
const httpRequest = (params) => { | |
return new Promise((resolve) => { | |
params.timeout = 30000; | |
params.onload = resolve; | |
params.onerror = resolve; | |
params.ontimeout = resolve; | |
params.onabort = resolve; | |
const func = typeof GM !== 'undefined' ? GM.xmlHttpRequest : GM_xmlhttpRequest; | |
func(params); | |
}); | |
}; | |
const getReviews = async (id) => { | |
const response = await httpRequest({ | |
method: 'GET', | |
url: `http://45.132.104.115/api/ali_bad_shops.php?shop_id=${id}` | |
}); | |
if (response.status !== 200) { | |
return null; | |
} | |
try { | |
return JSON.parse(response.responseText); | |
} catch (e) { | |
return null; | |
} | |
}; | |
const getDateString = (date) => { | |
if (!date) { | |
return '?'; | |
} | |
return new Date(date * 1000).toLocaleString('ru', { | |
year: 'numeric', | |
month: '2-digit', | |
day: '2-digit', | |
timezone: 'UTC', | |
hour: 'numeric', | |
minute: 'numeric' | |
}).replace(',', ''); | |
}; | |
const path = location.pathname.match(/^\/(item|i|store)\//); | |
if (!path) { | |
return; | |
} | |
let storeId; | |
switch (path[1]) { | |
case 'item': | |
storeId = unsafeWindow.runParams && unsafeWindow.runParams.data && unsafeWindow.runParams.data.actionModule && unsafeWindow.runParams.data.actionModule.storeNum; | |
break; | |
case 'i': | |
const link = document.querySelector('.store-link a'); | |
if (link) { | |
const m = link.href.match(/\/store\/(\d+)/); | |
if (m) { | |
storeId = m[1]; | |
} | |
} | |
break; | |
case 'store': | |
storeId = unsafeWindow.pageConfig && unsafeWindow.pageConfig.storeId; | |
break; | |
} | |
if (!storeId) { | |
return; | |
} | |
const style = document.createElement('style'); | |
style.innerHTML = ` | |
#asr-panel { | |
position: fixed; | |
display: flex; | |
flex-direction: column; | |
width: ${config.panelWidth}; | |
height: 100%; | |
top: 0; | |
left: 0; | |
transform: translateX(-100%); | |
z-index: 9999; | |
background-color: #f4f4f4; | |
box-shadow: 0 0 4px 1px #aeaeae; | |
border-radius: 0 6px 6px 0; | |
font-size: 14px; | |
transition: transform 0.5s; | |
} | |
#asr-panel[data-show] { | |
box-shadow: 0 0 15px 1px #808080; | |
transform: translateX(0); | |
} | |
#asr-panel .asr-header { | |
display: flex; | |
justify-content: center; | |
align-items: center; | |
padding: 4px 0; | |
margin-bottom: 4px; | |
background-color: #4a4a4a; | |
color: #fff; | |
font-weight: bold; | |
} | |
#asr-panel .asr-reviews { | |
flex-grow: 1; | |
padding: 0 4px; | |
margin-bottom: 4px; | |
overflow-y: auto; | |
overflow-x: hidden; | |
} | |
#asr-panel[data-result="good"] .asr-reviews, | |
#asr-panel[data-result="error"] .asr-reviews { | |
display: flex; | |
justify-content: center; | |
align-items: center; | |
} | |
#asr-panel .asr-review { | |
background-color: #eae9e9; | |
border: 2px solid #cecece; | |
border-radius: 4px; | |
} | |
#asr-panel .asr-review:not(:first-child) { | |
margin-top: 4px; | |
} | |
#asr-panel .asr-review-top { | |
display: flex; | |
padding: 4px; | |
background-color: #cecece; | |
color: #000; | |
text-decoration: none; | |
} | |
#asr-panel .asr-review-avatar { | |
width: 40px; | |
height: 40px; | |
margin-right: 8px; | |
background-size: contain; | |
background-repeat: no-repeat; | |
background-position-x: center; | |
} | |
#asr-panel .asr-review-info { | |
display: flex; | |
flex-direction: column; | |
justify-content: space-between; | |
flex-grow: 1; | |
} | |
#asr-panel .asr-review-user { | |
font-weight: bold; | |
} | |
#asr-panel .asr-review-message { | |
padding: 4px; | |
word-break: break-word; | |
} | |
#asr-panel .asr-center-message { | |
font-weight: bold; | |
margin: auto 0; | |
} | |
#asr-panel .asr-add-review { | |
display: flex; | |
justify-content: center; | |
align-items: center; | |
flex-shrink: 0; | |
height: 40px; | |
background-color: #4d9c4d; | |
color: #fff; | |
font-weight: bold; | |
text-shadow: 1px 1px 2px #444; | |
transition: background-color 0.5s; | |
} | |
#asr-panel .asr-add-review:hover { | |
text-decoration: none; | |
background-color: #65b365; | |
} | |
#asr-panel .asr-button { | |
position: absolute; | |
display: inline-flex; | |
justify-content: center; | |
align-items: center; | |
min-width: 30px; | |
height: 40px; | |
top: 50%; | |
right: 0; | |
transform: translate(100%, -50%); | |
padding: 0 6px 0 4px; | |
border-radius: 0 6px 6px 0; | |
border: 2px solid #fff; | |
border-left: none; | |
box-shadow: 0 0 15px 1px #808080; | |
clip-path: inset(-20px -20px -20px 0px); | |
color: #fff; | |
font-size: 16px; | |
font-weight: bold; | |
text-shadow: 1px 1px 2px #444; | |
cursor: default; | |
transition: background-color 0.5s; | |
} | |
#asr-panel[data-result="good"] .asr-button { | |
background-color: #00b33c; | |
} | |
#asr-panel[data-result="good"] .asr-button:hover { | |
background-color: #00cc44; | |
} | |
#asr-panel[data-result="bad"] .asr-button { | |
background-color: #f33; | |
} | |
#asr-panel[data-result="bad"] .asr-button:hover { | |
background-color: #ff5b5b; | |
} | |
#asr-panel[data-result="error"] .asr-button { | |
background-color: #9d9d9d; | |
} | |
#asr-panel[data-result="error"] .asr-button:hover { | |
background-color: #b3b3b3; | |
} | |
`; | |
document.head.appendChild(style); | |
const togglePanel = () => { | |
const show = () => { | |
panel.setAttribute('data-show', ''); | |
document.addEventListener('click', onDocumentClick); | |
}; | |
const hide = () => { | |
panel.removeAttribute('data-show'); | |
document.removeEventListener('click', onDocumentClick); | |
}; | |
const onDocumentClick = (e) => { | |
if (!panel.contains(e.target)) { | |
hide(); | |
} | |
}; | |
if (panel.hasAttribute('data-show')) { | |
hide(); | |
} else { | |
show(); | |
} | |
}; | |
const panel = document.createElement('div'); | |
panel.id = 'asr-panel'; | |
panel.innerHTML = ` | |
<div class="asr-header">Отзывы о продавце</div> | |
<div class="asr-reviews"></div> | |
<a class="asr-add-review" href="https://miped.ru/f/threads/93940/page-9999#QuickReply" target="_blank" rel="noopener noreferrer">Добавить отзыв</a> | |
<span class="asr-button" title="Отзывы о продавце"></span> | |
`; | |
const button = panel.querySelector('.asr-button'); | |
const messages = panel.querySelector('.asr-reviews'); | |
button.addEventListener('click', togglePanel); | |
const result = await getReviews(storeId); | |
if (!Array.isArray(result)) { | |
panel.setAttribute('data-result', 'error'); | |
button.innerText = '?'; | |
const message = document.createElement('div'); | |
message.className = 'asr-center-message'; | |
message.innerText = 'Не удалось получить отзывы'; | |
messages.appendChild(message); | |
} else if (!result.length) { | |
panel.setAttribute('data-result', 'good'); | |
button.innerText = '0'; | |
const message = document.createElement('div'); | |
message.className = 'asr-center-message'; | |
message.innerText = 'Нет отзывов'; | |
messages.appendChild(message); | |
} else { | |
panel.setAttribute('data-result', 'bad'); | |
button.innerText = result.length; | |
for (const i of result) { | |
const message = document.createElement('div'); | |
message.className = 'asr-review'; | |
message.innerHTML = ` | |
<a class="asr-review-top" href="${i.link}" target="_blank" rel="noopener noreferrer"> | |
<div class="asr-review-avatar" style="background-image: url(${i.avatar.includes('//') ? i.avatar : '//' + i.avatar})"></div> | |
<div class="asr-review-info"> | |
<div class="asr-review-user">${i.name}</div> | |
<div class="asr-review-date">${getDateString(i.date)}</div> | |
</div> | |
</a> | |
<div class="asr-review-message">${i.message.trim().replace(/\n/g, '<br>')}</div> | |
`; | |
messages.appendChild(message); | |
} | |
const links = panel.querySelectorAll('a'); | |
links.forEach((link) => { | |
link.addEventListener('click', () => { | |
link.href = link.href.replace(/\?[^#]+/, ''); | |
}); | |
}); | |
} | |
document.body.appendChild(panel); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment