// ==UserScript==
// @name Weixin Official Account Assistant
// @name:zh-CN 微信公众平台助手
// @name:ug ئۈندىدار سالون ياردەمچىسى
// @namespace https://github.com/ShererInc/Wx-OA-Assistant
// @version 1.1.1
// @author Sherer(شەرەر)
// @description Easy to get video ids(wxv), audio play url and image url in Weixin Official Accounts Platform
// @description:zh-CN 一键获取微信公众号视频素材ID(wxv),音频素材播放地址和图片地址
// @description:ug ئۈندىدار سالونىدىكى سىنلارنىڭ نومۇرى (wxv)، ئۈن قويۇش ئادرېسى ۋە رەسىم ئادرېسىغا ئاسانلا ئېرىشكىلى بولىدۇ
// @license MIT
// @supportURL https://github.com/ShererInc/Wx-OA-Assistant
// @match *://mp.weixin.qq.com/*
// @require https://unpkg.com/jquery@3.6.0/dist/jquery.min.js
// @require https://unpkg.com/sweetalert2@10.16.6/dist/sweetalert2.all.min.js
// @run-at document-idle
// @grant GM_setClipboard
// @grant GM_webRequest
// @grant GM_xmlhttpRequest
// @icon data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNTUxIiBoZWlnaHQ9IjU1MSIgdmlld0JveD0iMCAwIDU1MSA1NTEiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+DQo8bWFzayBpZD0ibWFzazBfMjVfOTIiIHN0eWxlPSJtYXNrLXR5cGU6YWxwaGEiIG1hc2tVbml0cz0idXNlclNwYWNlT25Vc2UiIHg9IjE1NCIgeT0iNzYiIHdpZHRoPSIyNTUiIGhlaWdodD0iMzk5Ij4NCjxwYXRoIGQ9Ik0xNTUuNDk2IDI3Ny41NjlDMTQzLjg2IDIyMy4xNjIgMzAwLjc5NyA3Ni40OTg0IDMwMC43OTcgNzYuNDk4NEMzMDAuNzk3IDc2LjQ5ODQgMjU4LjA4MyAxOTAuNDg4IDI3My4yNzkgMjQxLjc3QzI4OC40NzQgMjkzLjA1MyAzOTMuMTI1IDIyMS40NDcgNDA3LjUyNyAyNzcuNTY5QzQyMS45Mj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zZSI+DQo8c3RvcCBzdG9wLWNvbG9yPSIjRkY5OTAwIi8+DQo8c3RvcCBvZmZzZXQ9IjEiIHN0b3AtY29sb3I9IiNGQkFDNzMiLz4NCjwvbGluZWFyR3JhZGllbnQ+DQo8L2RlZnM+DQo8L3N2Zz4NCg==
// ==/UserScript==
(function () {
'use strict';
// global variables
const debug = false;
const lang = navigator.language || navigator.userLanguage; // e.g. "en-US"
const query = Object.fromEntries(new URLSearchParams(window.location.search)); // e.g. { type: "3", begin: "0", count: "20", token: "1412762085", lang: "zh_CN" }
const pathname = window.location.pathname; // e.g. "/cgi-bin/filepage"
// Language pack
const languages = {
'zh-CN': {
dir: 'ltr',
wxv: 'wxv',
url: '链接',
copy: '复制',
copyed: '内容已复制',
copy_url: '复制链接',
},
'ug': {
dir: 'rtl',
wxv: 'wxv',
url: 'ئۇلانمىسى',
copy: 'كۆچۈرۈش',
copyed: 'ئۇچۇر كۆچۈرۈلدى',
copy_url: 'ئۇلانمىنى كۆچۈرۈش',
},
'default': {
dir: 'ltr',
wxv: 'wxv',
url: 'URL',
copy: 'Copy',
copyed: 'content has been copied',
copy_url: 'Copy url',
},
};
// Use i18n
let tc = (key, locale = lang) => {
if (languages[locale] && languages[locale][key]) {
return languages[locale][key];
} else if (languages['default'] && languages['default'][key]) {
return languages['default'][key];
} else {
return key;
}
};
// Toast
let toast = Swal.mixin({
toast: true,
position: 'top',
showConfirmButton: false,
timer: 3500,
timerProgressBar: false,
customClass: {
container: `${tc('dir')} sherer-font`,
},
});
// Useful toast
const message = {
success: (text) => {
toast.fire({ title: text, icon: 'success' });
},
error: (text) => {
toast.fire({ title: text, icon: 'error' });
},
warning: (text) => {
toast.fire({ title: text, icon: 'warning' });
},
info: (text) => {
toast.fire({ title: text, icon: 'info' });
},
question: (text) => {
toast.fire({ title: text, icon: 'question' });
}
};
// Add style
let style = document.createElement('style');
style.innerHTML = `
.ltr { direction: ltr !important; }
.rtl { direction: rtl !important; }
.sherer-btn { cursor: pointer; background-color: #f5f5f5; padding: 5px 8px; border-radius: 3px; white-space: nowrap; }
.sherer-btn:hover { background-color: #e9e9e9; }
.sherer-font { font-family: 'UKIJ Ekran', 'UKIJ Tor', 'UKIJ Basma', 'ALKATIP Tor', 'ALKATIP', 'Microsoft YaHei', '微软雅黑', 'PingFang SC', 'Helvetica Neue', Helvetica, Arial, sans-serif !important; }
.sherer-flex-column { display: flex; flex-direction: column; }
.sherer-justify-between { justify-content: space-between; }
.sherer-position-none { position: static !important; }
.sherer-center { text-align: center; }
.sherer-ml-5 { margin-left: 5px !important; }
.sherer-mt-5 { margin-top: 5px !important; }
.sherer-border { border: 1px solid rgba(7,193,96,0.3); }
`;
document.head.appendChild(style);
// Parse video
const runVideo = (list) => {
if (pathname !== '/cgi-bin/appmsg') { return; }
if (!list || !list.length) { return; }
debug && console.log('run video', list);
// Insert wxv field in thead
let th = $(`<th class="sherer-wxv-th tc">${tc('wxv')}</th>`);
if (!$('.sherer-wxv-th').length) { $('.weui-desktop-table__hd').find('th').eq(0).after(th); }
// Insert wxv field in tbody
if ($('.sherer-wxv-td').length) { return; }
$('.weui-desktop-table__bd').find('tr').each(function (index) {
let tr = $(this);
let check = tr.find('.weui-desktop-simple-video__name-td');
if (!check.length) { return; }
let wxv = list[index].content;
if (!wxv) {
let url = list[index].content_url;
if (url) { wxv = (url.match(/vid=(\w*)/) || [''])[1]; }
}
let td = $(`<td><span class="sherer-wxv-td sherer-btn" data-content="${wxv || ''}">${wxv || ''}</span></td>`);
tr.find('td').eq(0).after(td);
});
// Set title field font
$('.weui-desktop-simple-video__title').addClass('sherer-font');
// Add copy all data button
if ($('.sherer-copy-all').length) { return; }
$('.weui-desktop-global__extra .weui-desktop-btn_wrp').find('button').eq(0).after(`<button type="button" class="weui-desktop-btn weui-desktop-btn_primary sherer-ml-5 sherer-copy-all sherer-font">${tc('copy')}</button>`);
$('.sherer-copy-all').off('click');
$('.sherer-copy-all').on('click', function () {
let content = JSON.stringify(list);
debug && console.log('copy text', content);
GM_setClipboard(content, 'text');
message.success(tc('copyed'));
});
};
// Parse audio
const runAudio = (list) => {
if (pathname !== '/cgi-bin/filepage' || query.type != 3) { return; }
if (!list || !list.length) { return; }
debug && console.log('run audio', list);
let view = query.view || 'card';
if (view == 'card') {
if ($('.weui-desktop-audio-picker__item').length > 0) { // New version
$('.weui-desktop-audio-picker__item').each(function (index) {
let div = $(this);
let fileid = list[index].voice_encode_fileid;
if (!fileid) { return; }
div.first().addClass('sherer-font sherer-flex-column');
let fileUrl = `https://res.wx.qq.com/voice/getvoice?mediaid=${fileid}`;
div.find('label').first().after(`<span class="sherer-fileid sherer-btn sherer-font sherer-center sherer-border sherer-mt-5" data-content="${fileUrl}">${tc('copy_url')}</span>`);
});
} else { // Old version
$('.weui-desktop-audio-card__info').each(function (index) {
let div = $(this);
let fileid = list[index].voice_encode_fileid;
if (!fileid) { return; }
div.addClass('sherer-font sherer-flex-column sherer-justify-between');
div.find('.weui-desktop-audio-card__item_left_bottom').addClass(`sherer-position-none`);
let fileUrl = `https://res.wx.qq.com/voice/getvoice?mediaid=${fileid}`;
div.find('strong').after(`<span class="sherer-fileid sherer-btn sherer-font sherer-center" data-content="${fileUrl}">${tc('copy_url')}</span>`);
});
}
} else if (view == 'list') {
// Insert fileid field in thead
let th = $(`<th class="sherer-fileid-th sherer-font tc">${tc('url')}</th>`);
if (!$('.sherer-fileid-th').length) { $('.weui-desktop-table-audio__content').after(th); }
// Insert fileid field in tbody
if ($('.sherer-fileid-td').length) { return; }
$('.weui-desktop-table__bd').find('tr').each(function (index) {
let tr = $(this);
let check = tr.find('.weui-desktop-audio-player__switch');
if (!check.length) { return; }
let fileid = list[index].voice_encode_fileid;
if (!fileid) { return; }
let fileUrl = `https://res.wx.qq.com/voice/getvoice?mediaid=${fileid}`;
let td = $(`<td><span class="sherer-fileid-td sherer-btn sherer-font" data-content="${fileUrl}">${tc('copy')}</span></td>`);
tr.find('td').eq(1).after(td);
});
// Set title field font
$('.weui-desktop-audio__title').addClass('sherer-font');
}
// Add copy all data button
if ($('.sherer-copy-all').length) { return; }
$('.weui-desktop-global__extra .weui-desktop-btn_wrp').find('button').eq(0).after(`<button type="button" class="weui-desktop-btn weui-desktop-btn_primary sherer-ml-5 sherer-copy-all sherer-font">${tc('copy')}</button>`);
$('.sherer-copy-all').off('click');
$('.sherer-copy-all').on('click', function () {
let content = JSON.stringify(list);
debug && console.log('copy text', content);
GM_setClipboard(content, 'text');
message.success(tc('copyed'));
});
};
// Parse image
// let imageTimer;
const runImage = (list) => {
if (pathname !== '/cgi-bin/filepage' || query.type != 2) { return; }
// if (imageTimer) clearTimeout(imageTimer);
if (!list || !list.length) { return; }
debug && console.log('run image', list);
$('.weui-desktop-img-picker__item').each(function (index) {
let div = $(this);
let cdn_url = list[index].cdn_url;
if (!cdn_url) { return; }
div.find('.sherer-cdn_url').remove();
div.append(`<div class="sherer-cdn_url sherer-btn sherer-font" data-content="${cdn_url}">${tc('copy_url')}</div>`)
});
// Insert cdn_url field in thead
let th = $(`<th class="sherer-cdn_url-th sherer-font tc">${tc('url')}</th>`);
if (!$('.sherer-cdn_url-th').length) { $('.weui-desktop-table__hd').find("th").eq(1).after(th); }
// Insert fileid field in tbody
$('.weui-desktop-table__bd').find('tr').each(function (index) {
let tr = $(this);
let check = tr.find('.weui-desktop-img-picker__img-title');
if (!check.length) { return; }
let cdn_url = list[index].cdn_url;
if (!cdn_url) { return; }
tr.find('.sherer-cdn_url-td').remove();
let td = $(`<td><span class="sherer-cdn_url-td sherer-btn sherer-font" data-content="${cdn_url}">${tc('copy')}</span></td>`);
tr.find('td').eq(1).after(td);
});
// Set title field font
$('.weui-desktop-image__title').removeClass('sherer-font').addClass('sherer-font');
activeCopyEvent();
// imageTimer = setTimeout(() => runImage(list), 500);
// Add copy all data button
if ($('.sherer-copy-all').length) { return; }
$('.weui-desktop-global__extra .weui-desktop-btn_wrp').find('button').eq(0).after(`<button type="button" class="weui-desktop-btn weui-desktop-btn_primary sherer-ml-5 sherer-copy-all sherer-font">${tc('copy')}</button>`);
$('.sherer-copy-all').off('click');
$('.sherer-copy-all').on('click', function () {
let content = JSON.stringify(list);
debug && console.log('copy text', content);
GM_setClipboard(content, 'text');
message.success(tc('copyed'));
});
};
// Add click event for copy content
const activeCopyEvent = () => {
$('.sherer-btn,.sherer-copy').off('click');
$('.sherer-btn,.sherer-copy').on('click', function () {
let content = $(this).data('content');
if (!content) { return; }
debug && console.log('copy text', content);
GM_setClipboard(content, 'text');
message.success(tc('copyed'));
});
}
// Run
runVideo((window?.wx?.cgiData || wx?.cgiData || {}).item);
runAudio((window?.wx?.cgiData || wx?.cgiData || {}).file_item);
runImage(((window?.wx?.cgiData || wx?.cgiData || {}).data || {}).file_item);
// active event
activeCopyEvent();
// Listen web request
let isFirst = true;
GM_webRequest([
{ selector: '*://mp.weixin.qq.com/cgi-bin/appmsg*', action: { redirect: { from: '([^:]+)://mp.weixin.qq.com/(.*)', to: '$1://mp.weixin.qq.com/$2' } } },
{ selector: '*://mp.weixin.qq.com/cgi-bin/filepage*type=2*', action: { redirect: { from: '([^:]+)://mp.weixin.qq.com/(.*)', to: '$1://mp.weixin.qq.com/$2' } } },
], function (info, message, details) {
if (info == 'redirect' && message == 'ok' && isFirst) {
isFirst = false;
setTimeout(() => isFirst = true, 10);
debug && console.log(info, message, details);
GM_xmlhttpRequest({
method: "GET",
url: details.url,
responseType: "json",
headers: { "Content-Type": "application/json" },
onload: function (response) {
debug && console.log(response);
runVideo((response?.response?.app_msg_info || {}).item);
runImage((response?.response?.page_info || {}).file_item);
}
});
}
});
})();