Skip to content

Commit

Permalink
quick fix for new zhihu-frontend
Browse files Browse the repository at this point in the history
other minor fixes
  • Loading branch information
XZiar committed Apr 20, 2018
1 parent 5937b22 commit 2888492
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 45 deletions.
4 changes: 4 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# 知乎疯牛病 --- 更新日志

## 1.0.7
* 知乎改前端啦,紧急修复
* 几个辅助页面的小修复

## 1.0.6
* 修复了部分“关注问题”不记录的问题。
* 文章也可以像回答一样保存了。
Expand Down
10 changes: 5 additions & 5 deletions DBExportor/POD.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,15 +220,15 @@ public class StandardDB
{
public List<Spam> spams = new List<Spam>();
public List<Follow> follows = new List<Follow>();
public List<User> users = new List<User>(3000000);
public List<User> users = new List<User>(4500000);
public List<Question> questions = new List<Question>();
public List<Article> articles = new List<Article>();
public List<Topic> topics = new List<Topic>();
public List<Answer> answers = new List<Answer>();
public List<Zan> zans = new List<Zan>(20000000);
public List<Zan> zanarts = new List<Zan>(3000000);
public List<Answer> answers = new List<Answer>(2000000);
public List<Zan> zans = new List<Zan>(23000000);
public List<Zan> zanarts = new List<Zan>(2000000);
public List<Zan> followqsts = new List<Zan>(100000);
public List<ADetail> details = new List<ADetail>();
public List<ADetail> details = new List<ADetail>(1500000);
public List<RecItem> rectime = new List<RecItem>();
public void Slim(int level = 0)
{
Expand Down
3 changes: 3 additions & 0 deletions ZhiHuExt.sln
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "template", "template", "{D3
ProjectSection(SolutionItems) = preProject
template\answers-api.json = template\answers-api.json
template\article-page.json = template\article-page.json
template\articles-api.json = template\articles-api.json
template\home-page.json = template\home-page.json
template\people-page.json = template\people-page.json
template\question-answers-api.json = template\question-answers-api.json
template\question-page.json = template\question-page.json
template\voters-api.json = template\voters-api.json
EndProjectSection
Expand Down
8 changes: 4 additions & 4 deletions ZhiHuExt/AssocAns.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,12 @@ function initSlider(data)
data.filter(x => x.date > 0).forEach(x => { mindate = Math.min(mindate, x.date); maxdate = Math.max(maxdate, x.date); });
rangetext.textContent = toDate(mindate) + " ~ " + toDate(maxdate);
const dateRange = { "min": [mindate], "max": [maxdate] };
if (mindate < maxdate - 3600 * 24 * 365)
if (mindate < maxdate - 3600 * 24 * 365) // a-year before
dateRange["5%"] = [maxdate - 3600 * 24 * 365];
if (mindate < maxdate - 3600 * 24 * 180)
if (mindate < maxdate - 3600 * 24 * 180) // 3-month before
dateRange["30%"] = [maxdate - 3600 * 24 * 180];
if (mindate < maxdate - 3600 * 24 * 30)
dateRange["60%"] = [maxdate - 3600 * 24 * 180];
if (mindate < maxdate - 3600 * 24 * 30) // a-month before
dateRange["60%"] = [maxdate - 3600 * 24 * 30];
noUiSlider.create(sliderHandle,
{
start: [0, maxdate],
Expand Down
36 changes: 19 additions & 17 deletions ZhiHuExt/ContentBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,12 @@ class ContentBase
return pms;
}
/**
* @param {string} uid
* @param {"followees" | "followers"} obj
* @param {string} uid
* @param {number} offset
* @returns {{data: User[], end: boolean, total: number}}
*/
static _fetchFollows(uid, obj, offset)
static _fetchFollows(obj, uid, offset)
{
const pms = $.Deferred();
ContentBase._get(`https://www.zhihu.com/api/v4/members/${uid}/${obj}?include=data[*].account_status,gender,voteup_count,answer_count,follower_count,is_followed,is_following,badge[?(type=best_answerer)].topics&limit=20&offset=${offset}`)
Expand Down Expand Up @@ -212,10 +212,10 @@ class ContentBase
}
catch (e)
{
if (++errcnt > 5)
break;
else
if (++errcnt <= 5)
continue;
console.warn("too many error occur when fetch voters, early return.", obj, id, limit, config);
break;
}
}
return ret;
Expand Down Expand Up @@ -278,17 +278,18 @@ class ContentBase
}
catch (e)
{
if (++errcnt > 5)
break;
else
if (++errcnt <= 5)
continue;
console.warn("too many error occur when fetch answers, early return.", qid, limit);
break;
}
}
return whole;
}

static async fetchComments(aid, limit)
{
let errcnt = 0;
const whole = [];
let isEnd = false;
for (let offset = 0; offset < limit && !isEnd;)
Expand All @@ -302,40 +303,41 @@ class ContentBase
}
catch (e)
{
if (++errcnt > 5)
break;
else
if (++errcnt <= 5)
continue;
console.warn("too many error occur when fetch comments, early return.", aid, limit);
break;
}
}
return whole;
}

/**
* @param {string} uid
* @param {"followees" | "followers"} obj
* @param {string} uid
* @param {number} limit
*/
static async fetchFollows(uid, obj, limit)
static async fetchFollows(obj, uid, limit)
{
let errcnt = 0;
/**@type {User[]}*/
const whole = [];
let isEnd = false;
for (let offset = 0; offset < limit && !isEnd;)
{
try
{
const part = await ContentBase._fetchFollows(uid, obj, offset);
const part = await ContentBase._fetchFollows(obj, uid, offset);
whole.push(...part.data);
isEnd = part.end;
offset += part.data.length;
}
catch (e)
{
if (++errcnt > 5)
break;
else
if (++errcnt <= 5)
continue;
console.warn("too many error occur when fetch follows, early return.", obj, uid, limit);
break;
}
}
/**@type {{users:User[],follows:Follow[]}}*/
Expand Down
4 changes: 2 additions & 2 deletions ZhiHuExt/PageEnhance.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,9 @@
const suffix = ev.currentTarget.href.split("/").pop();
let ret = null;
if (suffix === "following")
ret = await ContentBase.fetchFollows(uid, "followees", cnt);
ret = await ContentBase.fetchFollows("followees", uid, cnt);
else if (suffix === "followers")
ret = await ContentBase.fetchFollows(uid, "followers", cnt);
ret = await ContentBase.fetchFollows("followers", uid, cnt);
else
return;
ContentBase._report("follow", ret);
Expand Down
5 changes: 4 additions & 1 deletion ZhiHuExt/StatVoter.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ async function StatVoters(...voters)
/**
* @param {User} objuser
* @param {HTMLAnchorElement} anchor
* @param {number} deep
* @param {boolean} deep
*/
async function chkUser(objuser, anchor, deep)
{
Expand All @@ -75,7 +75,10 @@ async function chkUser(objuser, anchor, deep)
return;
finalUserMap[user.id] = user;
if (user.status === "ban" || user.status === "sban")
{
anchor.style.background = "red";
await ContentBase.checkUserState(objuser.id, undefined, [250], true);//extra check
}
}

$(document).on("click", "#chkAllStatus", async e =>
Expand Down
47 changes: 32 additions & 15 deletions ZhiHuExt/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,39 +263,56 @@ function monitorVoter(voterPopup)
}
}

/**
* Add "Analyse" and "ReportSpam" buttons for each ".List-item"
* @param {HTMLDivElement[]} answerNodes
*/
function addAASpamBtns(answerNodes)
{
answerNodes.filter(node => !node.hasChild(".Btn-ReportSpam"))
.forEach(node =>
{
if (!node) return;
/**@type {{type: string, token: string, upvote_num: number, comment_num: number, parent_token: string, author_member_hash_id: string}}*/
const ansInfo = JSON.parse(node.dataset.zaModuleInfo || node.dataset.zaExtraModule).card.content;
let thetype;
if (ansInfo.type === "Answer")
thetype = "answer";
else if (ansInfo.type === "Post")
thetype = "article";
let ansInfo;
try
{
const oldInfo = node.dataset.zaModuleInfo || node.dataset.zaExtraModule;
if (oldInfo)
ansInfo = JSON.parse(oldInfo).card.content;
else
ansInfo = JSON.parse(node.dataset.zop);
}
catch (e)
{
console.warn("in paring for AASpamBtn, Zhihu may have update API", node.dataset);
return;
}
let atype;
if (ansInfo.type === "Answer" || ansInfo.type === "answer")
atype = "answer";
else if (ansInfo.type === "Post" || ansInfo.type === "article")
atype = "article";
else
return;

const ansid = ansInfo.token;
const ansArea = node.querySelector(".AuthorInfo");
if (!ansArea)
const aid = ansInfo.token || ansInfo.itemId;
const aArea = node.querySelector(".AuthorInfo");
if (!aArea)
return;
{
const btn = createButton(["Btn-CheckSpam", "Button--primary"], "分析");
btn.dataset.id = ansid;
btn.dataset.type = thetype;
btn.dataset.id = aid;
btn.dataset.type = atype;
setDraggable(btn);
ansArea.appendChild(btn);
aArea.appendChild(btn);
}
{
const btn = createButton(["Btn-ReportSpam", "Button--primary"], "广告");
btn.dataset.id = ansid;
btn.dataset.type = thetype;
btn.dataset.id = aid;
btn.dataset.type = atype;
setDraggable(btn);
ansArea.appendChild(btn);
aArea.appendChild(btn);
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion ZhiHuExt/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"manifest_version": 2,
"name": "知乎疯牛病",
"key": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAmYNx4WYJ0FifJIs5ojnD8St4/3gAbskGThOD4bVn7yPWNce9ZC5/vRIzVNBKeJ8iCfQlQJ9EZq4HUngDGesM9KvpdCKTpB38yceOOlPumx9jN30Oq6IuTwdZsDnDl62mDi+phvQ4XMuPMUvAlxqfeotdf1KxmWGWzoqlZwq+1K/atTco4c4bUPotDtzo6D80B7SBAYrug8L+/crZtfUR44T2MnaBy8GG9f+6+kwQQ3pi4ehb7bLMdyxKEZhCSN+r8SdVaz+mTMzPpEt3M0tdCFen6WWw4HH8gZk9hb7v/WkWVxsFN1pHe7LRv8/28+Cig8cKGjCfwoFBgHLdYE/FyQIDAQAB",
"version": "1.0.6",
"version": "1.0.7",
"author": "XZiar",
"description": "知乎疯牛病插件————专治广告(并不能)",
"icons":
Expand Down

0 comments on commit 2888492

Please sign in to comment.