') !== '7';
});
// @@replace logic
fixRegExpWellKnownSymbolLogic('replace', function (_, nativeReplace, maybeCallNative) {
var UNSAFE_SUBSTITUTE = REGEXP_REPLACE_SUBSTITUTES_UNDEFINED_CAPTURE ? '$' : '$0';
return [
// `String.prototype.replace` method
// https://tc39.es/ecma262/#sec-string.prototype.replace
function replace(searchValue, replaceValue) {
var O = requireObjectCoercible(this);
var replacer = searchValue == undefined ? undefined : searchValue[REPLACE];
return replacer !== undefined
? replacer.call(searchValue, O, replaceValue)
: nativeReplace.call(toString(O), searchValue, replaceValue);
},
// `RegExp.prototype[@@replace]` method
// https://tc39.es/ecma262/#sec-regexp.prototype-@@replace
function (string, replaceValue) {
var rx = anObject(this);
var S = toString(string);
if (
typeof replaceValue === 'string' &&
replaceValue.indexOf(UNSAFE_SUBSTITUTE) === -1 &&
replaceValue.indexOf('$<') === -1
) {
var res = maybeCallNative(nativeReplace, rx, S, replaceValue);
if (res.done) return res.value;
}
var functionalReplace = typeof replaceValue === 'function';
if (!functionalReplace) replaceValue = toString(replaceValue);
var global = rx.global;
if (global) {
var fullUnicode = rx.unicode;
rx.lastIndex = 0;
}
var results = [];
while (true) {
var result = regExpExec(rx, S);
if (result === null) break;
results.push(result);
if (!global) break;
var matchStr = toString(result[0]);
if (matchStr === '') rx.lastIndex = advanceStringIndex(S, toLength(rx.lastIndex), fullUnicode);
}
var accumulatedResult = '';
var nextSourcePosition = 0;
for (var i = 0; i < results.length; i++) {
result = results[i];
var matched = toString(result[0]);
var position = max(min(toInteger(result.index), S.length), 0);
var captures = [];
// NOTE: This is equivalent to
// captures = result.slice(1).map(maybeToString)
// but for some reason `nativeSlice.call(result, 1, result.length)` (called in
// the slice polyfill when slicing native arrays) "doesn't work" in safari 9 and
// causes a crash (https://pastebin.com/N21QzeQA) when trying to debug it.
for (var j = 1; j < result.length; j++) captures.push(maybeToString(result[j]));
var namedCaptures = result.groups;
if (functionalReplace) {
var replacerArgs = [matched].concat(captures, position, S);
if (namedCaptures !== undefined) replacerArgs.push(namedCaptures);
var replacement = toString(replaceValue.apply(undefined, replacerArgs));
} else {
replacement = getSubstitution(matched, S, position, captures, namedCaptures, replaceValue);
}
if (position >= nextSourcePosition) {
accumulatedResult += S.slice(nextSourcePosition, position) + replacement;
nextSourcePosition = position + matched.length;
}
}
return accumulatedResult + S.slice(nextSourcePosition);
}
];
}, !REPLACE_SUPPORTS_NAMED_GROUPS || !REPLACE_KEEPS_$0 || REGEXP_REPLACE_SUBSTITUTES_UNDEFINED_CAPTURE);
var blockTopics = [
"树洞一下",
"掘金相亲角",
"反馈 & 建议",
"沸点福利",
"掘金官方",
"上班摸鱼"
];
var scriptId$1 = "juejin-activies-enhancer/break-the-circle";
var startTimeStamp = "1632326400000";
var endTimeStamp = "1633017600000";
const states$1 = {
userId: ""
};
function getUserId() {
return states$1.userId;
}
function setUserId(userId) {
states$1.userId = userId;
}
const scriptId = "juejin-activies-enhancer";
const inPinPage = pathname => {
return /^\/pins(?:\/|$)/.test(pathname);
};
const inProfilePage = pathname => {
return new RegExp(`^\\/user\\/${getUserId()}(?:\\/|$)`).test(pathname);
};
function fetchData({
url,
data = {}
}) {
return new Promise((resolve, reject) => {
GM_xmlhttpRequest({
method: "POST",
url,
data: JSON.stringify({
user_id: getUserId(),
...data
}),
headers: {
"User-agent": window.navigator.userAgent,
"content-type": "application/json"
},
onload: function ({
status,
response
}) {
try {
if (status === 200) {
const responseData = JSON.parse(response);
resolve(responseData);
} else {
reject(response);
}
} catch (err) {
console.log(err);
reject(err);
}
}
});
});
}
class ProfileStatRender {
constructor() {
const blockEl = document.createElement("div");
blockEl.dataset.tampermonkey = scriptId;
blockEl.className = "block shadow";
blockEl.style = `margin-bottom: 1rem;background-color: #fff;border-radius: 2px;`;
const titleEl = document.createElement("div");
titleEl.style = `padding: 1.333rem;
font-size: 1.333rem;
font-weight: 600;
color: #31445b;
border-bottom: 1px solid rgba(230,230,231,.5);`;
titleEl.textContent = "活动状态";
blockEl.appendChild(titleEl);
const contentEl = document.createElement("div");
contentEl.style = `padding: 1.333rem;`;
blockEl.appendChild(contentEl);
this.blockEl = blockEl;
this.contentEl = contentEl;
this.data = [];
}
add(data) {
const now = new Date().valueOf();
this.data.push(data);
this.data.sort((a, b) => {
const isFinishA = a.endTime > now;
const isFinishB = b.endTime > now;
if (isFinishA && !isFinishB) return -1;else if (isFinishB && !isFinishA) return 1;
return b.startTime - a.startTime;
});
this.render();
}
render() {
const container = this.contentEl;
const currentDOM = container.children;
this.data.forEach(({
node
}, index) => {
const element = currentDOM[index];
if (!element) {
container.appendChild(node);
return;
}
if (element !== node) {
element.replaceWith(node);
}
});
for (let i = this.data.length, len = currentDOM.length; i < len; i++) {
container.removeChild(currentDOM[i]);
}
if (!this.blockEl.isConnected) {
const siblingEl = document.querySelector(".user-view .stat-block");
const parentEl = document.querySelector(".user-view .sticky-wrap");
if (siblingEl) {
var _siblingEl$parentElem;
(_siblingEl$parentElem = siblingEl.parentElement.querySelector(`[data-tampermonkey='${scriptId}']`)) === null || _siblingEl$parentElem === void 0 ? void 0 : _siblingEl$parentElem.remove();
siblingEl.after(this.blockEl);
return;
}
if (parentEl) {
var _parentEl$querySelect;
(_parentEl$querySelect = parentEl.querySelector(`[data-tampermonkey='${scriptId}']`)) === null || _parentEl$querySelect === void 0 ? void 0 : _parentEl$querySelect.remove();
parentEl.firstChild ? parentEl.insertBefore(this.blockEl, parentEl.firstChild) : parentEl.appendChild(this.blockEl);
}
}
}
}
const profileStateRender = new ProfileStatRender();
const states = GM_getValue(scriptId$1, {
checkPoint: 0,
topics: {
todayEfficientTopicTitles: [],
efficientDays: 0,
efficientTopics: {}
}
});
function getCheckPoint() {
return states.checkPoint;
}
function getTopicStates() {
return states.topics;
}
function setTopicStates(value) {
states.checkPoint = new Date().valueOf();
states.topics = value;
GM_setValue(scriptId$1, states);
}
async function fetchStates() {
if (getCheckPoint() > endTimeStamp) {
return new Promise(resolve => {
setTimeout(() => {
resolve(getTopicStates());
});
});
}
const dailyTopics = await requestShortMsgTopic();
updateGlobalStates(dailyTopics);
}
function requestShortMsgTopic(cursor = "0", dailyTopics = []) {
return fetchData({
url: "https://api.juejin.cn/content_api/v1/short_msg/query_list",
data: {
sort_type: 4,
limit: 24,
cursor
}
}).then(responseData => {
const {
data,
cursor,
has_more
} = responseData;
let lastPublishTime = Infinity;
if (data) {
for (const msg of data) {
const {
topic,
msg_Info
} = msg;
const publishTime = msg_Info.ctime * 1000;
if (publishTime > startTimeStamp && publishTime < endTimeStamp && !blockTopics.includes(topic.title)) {
const day = Math.floor((publishTime - startTimeStamp) / 86400000);
if (!dailyTopics[day]) {
dailyTopics[day] = [];
}
dailyTopics[day].push({
title: topic.title,
// wait: 0, pass: 1, fail: 2
verified: msg_Info.verify_status === 0 ? 0 : msg_Info.audit_status === 2 && msg_Info.verify_status === 1 ? 1 : 2
});
}
lastPublishTime = publishTime;
if (publishTime < startTimeStamp) {
break;
}
}
}
if (lastPublishTime > startTimeStamp && has_more) {
return requestShortMsgTopic(cursor, dailyTopics);
} else {
return dailyTopics;
}
});
}
function updateGlobalStates(dailyTopics) {
const allEfficientTopicTitles = new Set();
const topicCountAndVerified = {};
const todayIndex = Math.floor((new Date().valueOf() - startTimeStamp) / 86400000);
const todayEfficientTopicTitles = [];
let efficientDays = 0;
dailyTopics.forEach((topics, index) => {
// 获取一天破解的圈子
const dailyEfficientTopicTitles = new Set(topics.filter(({
title,
verified
}) => {
// 破圈:未被破解 + 已通过审核或正在等待审核
return !allEfficientTopicTitles.has(title) && verified !== 2;
}).map(({
title
}) => title));
const dailyVerifiedTopicTitles = new Set(topics.filter(({
title,
verified
}) => {
// 破圈:未被破解 + 已通过审核或正在等待审核
return !allEfficientTopicTitles.has(title) && verified === 1;
})); // 更新达标天数
if (dailyVerifiedTopicTitles.size >= 3) {
efficientDays++;
} // 记录今日破圈数据
if (index === todayIndex) {
todayEfficientTopicTitles.push(...dailyEfficientTopicTitles);
} // 更新已破圈集合
dailyEfficientTopicTitles.forEach(t => allEfficientTopicTitles.add(t)); // 记录已破圈发帖数
topics.map(({
title,
verified
}) => {
if (!topicCountAndVerified[title]) {
topicCountAndVerified[title] = {
count: 1,
verified
};
} else {
var _topicCountAndVerifie, _verified;
topicCountAndVerified[title]["count"]++;
(_topicCountAndVerifie = topicCountAndVerified[title])[_verified = "verified"] || (_topicCountAndVerifie[_verified] = verified === 1);
}
});
});
setTopicStates({
todayEfficientTopicTitles,
efficientDays,
efficientTopics: Object.fromEntries([...allEfficientTopicTitles].map(title => {
return [title, topicCountAndVerified[title]];
}))
});
}
function renderPinPage() {
var _containerEl$querySel;
const containerEl = document.querySelector(".main .userbox");
if (!containerEl) {
return;
}
(_containerEl$querySel = containerEl.querySelector(`[data-tampermonkey='${scriptId$1}']`)) === null || _containerEl$querySel === void 0 ? void 0 : _containerEl$querySel.remove();
const wrapperEl = document.createElement("div");
wrapperEl.dataset.tampermonkey = scriptId$1;
wrapperEl.appendChild(getRewardElement());
wrapperEl.style = "padding-top:20px;";
containerEl.appendChild(wrapperEl);
}
function renderProfilePage() {
profileStateRender.add({
startTime: new Date(startTimeStamp),
endTime: new Date(endTimeStamp),
node: getRewardElement()
});
}
function getRewardElement() {
const {
efficientTopics,
efficientDays
} = getTopicStates();
const topicCount = Object.values(efficientTopics).filter(({
verified
}) => !!verified).length;
const reward = ["幸运奖", "三等奖", "二等奖", "一等奖", "全勤奖"][efficientDays >= 8 ? 4 : Math.floor((efficientDays - 1) / 2)] ?? (topicCount > 1 ? "幸运奖" : "无");
const descriptionHTML = [`🎯 达成 ${efficientDays} 天`, `⭕ ${topicCount} 个圈子`, `🏆 ${reward}`].map(text => `${text}`).join("");
const rewardEl = document.createElement("div");
rewardEl.innerHTML = `破圈行动 9/23 - 9/30
${descriptionHTML}
${endTimeStamp < new Date().valueOf() || efficientDays >= 8 ? getFinishSummary({
isJoined: topicCount > 0
}) : getTodayStatus()}
`;
return rewardEl;
}
function getTodayStatus() {
const {
todayEfficientTopicTitles,
efficientTopics
} = getTopicStates();
const todayTopicsHTML = todayEfficientTopicTitles.map(title => {
var _efficientTopics$titl;
const isVerified = (_efficientTopics$titl = efficientTopics[title]) === null || _efficientTopics$titl === void 0 ? void 0 : _efficientTopics$titl.verified;
return renderTag(title, isVerified);
}).join("");
const todayVerifiedCount = todayEfficientTopicTitles.filter(title => {
var _efficientTopics$titl2;
return (_efficientTopics$titl2 = efficientTopics[title]) === null || _efficientTopics$titl2 === void 0 ? void 0 : _efficientTopics$titl2.verified;
}).length;
const todayVerifyCount = todayEfficientTopicTitles.length - todayVerifiedCount;
return `📅 今天 ${todayVerifiedCount} / 3 ${todayVerifyCount > 0 ? ` 🧐 人工审核中 ${todayVerifyCount} 条` : ""}
${todayTopicsHTML}
`;
}
function getFinishSummary({
isJoined
}) {
const {
efficientTopics
} = getTopicStates();
if (isJoined) {
return `
🎉 恭喜完成活动!展开查看破解列表
${Object.keys(efficientTopics).map(title => {
return renderTag(title);
}).join("")}
`;
} else {
return `⌛️ 活动已结束
`;
}
}
function renderTag(title, isVerified = true) {
return `${title}`;
}
function renderTopicSelectMenu(containerEl) {
if (endTimeStamp < new Date().valueOf()) return;
const topicPanel = containerEl.querySelector(".topicwrapper .new_topic_picker");
if (!topicPanel) {
return;
}
const observer = new MutationObserver(function (mutations) {
mutations.forEach(({
type,
addedNodes
}) => {
if (type === "childList" && addedNodes.length) {
addedNodes.forEach(itemEl => {
var _itemEl$classList;
if (!itemEl) return;else if (itemEl !== null && itemEl !== void 0 && (_itemEl$classList = itemEl.classList) !== null && _itemEl$classList !== void 0 && _itemEl$classList.contains("contents")) {
renderWholeContent(itemEl);
} else {
renderItem(itemEl);
}
});
}
});
});
observer.observe(topicPanel, {
childList: true,
subtree: true
});
renderWholeContent(topicPanel.querySelector(".wrapper .contents"));
}
function renderWholeContent(contentEl) {
if (!contentEl) {
return;
}
const allItemEls = contentEl.querySelectorAll(".item");
allItemEls.forEach(itemEl => {
renderItem(itemEl);
});
}
function renderItem(itemEl) {
var _itemEl$parentElement, _itemEl$parentElement2, _itemEl$querySelector, _itemEl$querySelector2, _efficientTopics$titl, _efficientTopics$titl2;
const {
efficientTopics
} = getTopicStates();
if (!itemEl || !(itemEl.nodeType === 1 && itemEl.nodeName === "DIV" && itemEl.classList.contains("item")) || !((_itemEl$parentElement = itemEl.parentElement) !== null && _itemEl$parentElement !== void 0 && _itemEl$parentElement.classList.contains("contents")) && !((_itemEl$parentElement2 = itemEl.parentElement) !== null && _itemEl$parentElement2 !== void 0 && _itemEl$parentElement2.classList.contains("searchlist"))) return;
(_itemEl$querySelector = itemEl.querySelector(`[data-tampermonkey='${scriptId$1}']`)) === null || _itemEl$querySelector === void 0 ? void 0 : _itemEl$querySelector.remove();
const title = (_itemEl$querySelector2 = itemEl.querySelector(".content_main > .title")) === null || _itemEl$querySelector2 === void 0 ? void 0 : _itemEl$querySelector2.textContent;
const isBlockedTopic = blockTopics.includes(title);
const count = (_efficientTopics$titl = efficientTopics[title]) === null || _efficientTopics$titl === void 0 ? void 0 : _efficientTopics$titl.count;
const verified = (_efficientTopics$titl2 = efficientTopics[title]) === null || _efficientTopics$titl2 === void 0 ? void 0 : _efficientTopics$titl2.verified;
const iconEl = document.createElement("div");
iconEl.dataset.tampermonkey = scriptId$1;
if (count) {
iconEl.style = `width: 18px;
height: 18px;
overflow: hidden;
border-radius: 50%;
background-color: ${!verified ? "#939aa3" : "#0fbf60"};
color: #fff;
font-size: 12px;
text-align: center;
line-height: 18px;
font-weight: bold;
font-family: monospace;
margin-left: auto;
margin-right: 15px;`;
iconEl.innerText = count;
} else {
iconEl.style = `margin-left: auto;margin-right: 15px;color: #c2c6cc`;
if (isBlockedTopic) {
iconEl.innerHTML = ``;
} else {
iconEl.innerHTML = ``;
}
}
itemEl.appendChild(iconEl);
}
function onRouteChange$1(prevRouterPathname, currentRouterPathname) {
if (inPinPage(currentRouterPathname) && !inPinPage(prevRouterPathname)) {
fetchStates().then(() => {
renderTopicSelectMenu(document);
renderPinPage();
});
} else if (inProfilePage(currentRouterPathname) && !inProfilePage(prevRouterPathname)) {
fetchStates().then(() => {
setTimeout(() => {
renderProfilePage();
}, 1000);
});
}
}
function initPopupMutation() {
const componentBoxEl = document.querySelector(".global-component-box");
if (componentBoxEl) {
const observer = new MutationObserver(function (mutations) {
const mutation = mutations.find(mutation => {
const {
type,
addedNodes
} = mutation;
if (type === "childList" && Array.prototype.find.call(addedNodes, node => {
var _node$classList;
return (_node$classList = node.classList) === null || _node$classList === void 0 ? void 0 : _node$classList.contains("pin-modal");
})) {
return true;
} else {
return false;
}
});
if (mutation) {
mutation.addedNodes.forEach(node => {
var _node$classList2;
if ((_node$classList2 = node.classList) !== null && _node$classList2 !== void 0 && _node$classList2.contains("pin-modal")) {
fetchStates().then(() => {
renderTopicSelectMenu(node);
});
}
});
}
});
observer.observe(componentBoxEl, {
childList: true
});
}
}
var BreakTheCycle = {
onRouteChange: onRouteChange$1,
onLoaded: initPopupMutation
};
const activities = [BreakTheCycle];
let currentRouterPathname = "";
(function start() {
const userProfileEl = document.querySelector(".user-dropdown-list > .nav-menu-item-group:nth-child(2) > .nav-menu-item > a[href]");
const userId = userProfileEl === null || userProfileEl === void 0 ? void 0 : userProfileEl.getAttribute("href").replace(/\/user\//, "");
if (!userId) {
return;
}
setUserId(userId);
initRouter();
activities.forEach(({
onLoaded
}) => onLoaded === null || onLoaded === void 0 ? void 0 : onLoaded());
})();
function initRouter() {
const _historyPushState = history.pushState;
const _historyReplaceState = history.replaceState;
history.pushState = function () {
_historyPushState.apply(history, arguments);
onRouteChange();
};
history.replaceState = function () {
_historyReplaceState.apply(history, arguments);
onRouteChange();
};
window.addEventListener("popstate", function () {
onRouteChange();
});
}
function onRouteChange() {
const prevRouterPathname = currentRouterPathname;
currentRouterPathname = document.location.pathname;
if (prevRouterPathname !== currentRouterPathname) {
activities.forEach(({
onRouteChange
}) => {
onRouteChange === null || onRouteChange === void 0 ? void 0 : onRouteChange(prevRouterPathname, currentRouterPathname);
});
}
}
})();