|
4 | 4 | let finalUserMap;
|
5 | 5 | /**@type {SimpleBag}*/
|
6 | 6 | let finalBag;
|
| 7 | +let CUR_ANSWER, CUR_ |
| 8 | + |
| 9 | +function reportSpam(id, type) |
| 10 | +{ |
| 11 | + const payload = { "resource_id": id, "type": type, "reason_type": "spam", "source": "web" }; |
| 12 | + //req.setRequestHeader("Referer", "https://www.zhihu.com/people/" + id + "/activities"); |
| 13 | + const pms = $.Deferred(); |
| 14 | + ContentBase._post("https://www.zhihu.com/api/v4/reports", payload) |
| 15 | + .done((data, status, xhr) => |
| 16 | + { |
| 17 | + if (xhr.status === 204 || xhr.status === 200) |
| 18 | + { |
| 19 | + pms.resolve(); |
| 20 | + ContentBase._report("spams", { id: id, type: type }); |
| 21 | + } |
| 22 | + }) |
| 23 | + .fail((data, status, xhr) => |
| 24 | + { |
| 25 | + if (data.responseJSON) |
| 26 | + pms.reject({ code: data.responseJSON.error.code, error: data.responseJSON.error.message }); |
| 27 | + else |
| 28 | + pms.reject({ code: xhr.status, error: "unknown error" }); |
| 29 | + }) |
| 30 | + return pms; |
| 31 | +} |
7 | 32 |
|
8 | 33 | /**
|
9 | 34 | * @param {...BagArray} voters
|
@@ -37,14 +62,15 @@ async function StatVoters(...voters)
|
37 | 62 | {
|
38 | 63 | paging: true,
|
39 | 64 | deferRender: true,
|
40 |
| - lengthMenu: [[20, 50, 100, -1], [20, 50, 100, "All"]], |
| 65 | + lengthMenu: [[20, 100, 200, -1], [20, 100, 200, "All"]], |
41 | 66 | data: data,
|
42 | 67 | order: [[6, "desc"], [5, "desc"], [1, "asc"]],
|
43 | 68 | columns:
|
44 | 69 | [
|
45 | 70 | {
|
46 | 71 | data: "usr",
|
47 |
| - render: displayRender(dat => `<a class="bgopen usr" data-id="${dat.id}" href="https://www.zhihu.com/people/${dat.id}">${dat.name}</a>`) |
| 72 | + render: displayRender(dat => `<a class="bgopen usr" data-id="${dat.id}" href="https://www.zhihu.com/people/${dat.id}">${dat.name}</a> |
| 73 | + <button class="Btn-ReportSpam" data-id="${dat.id}" data-type="member">广告</button>`) |
48 | 74 | },
|
49 | 75 | {
|
50 | 76 | data: "status",
|
@@ -118,7 +144,47 @@ $(document).on("click", "#copyusr", e =>
|
118 | 144 | const request = { action: "copy", data: JSON.stringify(finalBag.elements()) };
|
119 | 145 | SendMsgAsync(request);
|
120 | 146 | });
|
121 |
| - |
| 147 | +$("body").on("click", "button.Btn-ReportSpam", e => |
| 148 | +{ |
| 149 | + const btn = e.target; |
| 150 | + reportSpam(btn.dataset.id, btn.dataset.type) |
| 151 | + .done(() => btn.style.backgroundColor = "rgb(0,224,32)") |
| 152 | + .fail((e) => |
| 153 | + { |
| 154 | + console.warn("report fail:" + e.code, e.error); |
| 155 | + if (e.code === 103001)//repeat |
| 156 | + btn.style.backgroundColor = "rgb(224,224,32)"; |
| 157 | + else if (e.code === 4039)//need verify |
| 158 | + btn.style.backgroundColor = "rgb(32,64,192)"; |
| 159 | + else |
| 160 | + btn.style.backgroundColor = "rgb(224,0,32)"; |
| 161 | + }); |
| 162 | +}); |
| 163 | +$("body").on("click", "button.Btn-Similarity", e => |
| 164 | +{ |
| 165 | + const thisbtn = e.target; |
| 166 | + const msg = { action: "chksim", target: "user", data: null }; |
| 167 | + /**@type {HTMLButtonElement[]}*/ |
| 168 | + const btns = $("#maintable").find("button.Btn-ReportSpam").toArray(); |
| 169 | + console.log("detect " + btns.length + " user"); |
| 170 | + chrome.runtime.sendMessage(msg, /**@param {[string, [number, number, number]][]} result*/(result) => |
| 171 | + { |
| 172 | + console.log(result); |
| 173 | + const simmap = new Map(result.data); |
| 174 | + let maxcnt = 0; |
| 175 | + btns.forEach(btn => |
| 176 | + { |
| 177 | + const counts = simmap.get(btn.dataset.id); |
| 178 | + btn.textContent = `${counts[0]}(${counts[1]})/${counts[2]}`; |
| 179 | + btn.style.fontSize = "smaller"; |
| 180 | + btn.style.fontWeight = "bold"; |
| 181 | + maxcnt = Math.max(maxcnt, counts[0]); |
| 182 | + }); |
| 183 | + thisbtn.textContent = `${maxcnt}(${result.limit})`; |
| 184 | + thisbtn.style.fontSize = "smaller"; |
| 185 | + thisbtn.style.fontWeight = "bold"; |
| 186 | + }); |
| 187 | +}); |
122 | 188 |
|
123 | 189 | !async function()
|
124 | 190 | {
|
|
0 commit comments