Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * 아래 userMatrix 의 형식에 주의하세요. 2개 이상을 입력한 경우, 마지막 줄에는 , 이 없어야 합니다.
- * 따옴표 안에는 따옴표를 제외한 아무 내용이나 넣어도 괜찮습니다.
- * var userMaterix = {
- * 646: "고펑", // 두개 이상의 id 를 추가하려면 줄 끝에 콤마(,) 를 넣어야 합니다.
- * 9999: "자지보지섹스얍얍" // 마지막 줄의 끝에는 콤마(,) 가 없어야 합니다. 콤마가 있을 경우 스크립트가 동작하지 않을 수 있습니다.
- * }
- */
- var userMatrix = {
- };
- // 게시글 xPath 정의
- var XPATH_POSTS_TABLE = "//*[@id='revolution_main_table']/tbody[2]";
- var XPATH_CONTENT_WITH_REPLIES = "/html/body/div[2]/div[2]";
- var XPATH_VIEW_ALL_REPLIES = "/html/body/div[2]/div[2]/table[10]/tbody/tr/td/p/a";
- // 화면 모드 정의.
- var SCREEN_MODE_TITLE_GENERAL = "zboard.php";
- var SCREEN_MODE_DETAILS = "view.php";
- var SCREEN_MODE_TITLE_HOF = "best_pc.php";
- var SCREEN_MODES = [
- SCREEN_MODE_TITLE_GENERAL, SCREEN_MODE_DETAILS, SCREEN_MODE_TITLE_HOF
- ];
- // 메인 프로그램
- function main() {
- // 화면 모드 먼저 판별하는 이유는 불필요한 연산 조금이라도 줄이기 위함
- const screenMode = function() {
- const pathFragments = document.location.pathname.split("/");
- const lastPath = pathFragments[pathFragments.length - 1];
- for (const value of SCREEN_MODES) {
- if(value === lastPath) {
- return value;
- }
- }
- return null;
- }();
- if (screenMode == null) {
- console.error(`URL 형식이 변경되어 더 이상 진행할 수 없습니다.`);
- return;
- }
- // zbLayerId 와 일치하는 memberId 사전 생성
- const layerIdMap = buildLayerIdMap();
- if (layerIdMap.length === 0) {
- console.error(`Document 형식이 변경되어 더 이상 진행할 수 없습니다.`);
- return;
- }
- // 화면 모드에 따라 프로그램 진행
- switch(screenMode) {
- case SCREEN_MODE_TITLE_GENERAL: {
- const table = getElementByXpath(XPATH_POSTS_TABLE);
- const tableRowsCount = table.children.length;
- const postsCount = Array.from(table.children).filter(it => {
- return it.children.length == 5;
- }).length;
- const trOffset = tableRowsCount - postsCount;
- removePosts(layerIdMap, postsCount, trOffset);
- }
- break;
- case SCREEN_MODE_DETAILS: {
- const [replyXpathOffset, replyDomOffset] = function() {
- // Parent DOM 으로부터 제일 첫번째 댓글이 보이는 Element offset 을 구한다.
- if (getElementByXpath(XPATH_VIEW_ALL_REPLIES)) {
- return [11, 39];
- } else {
- return [9, 29];
- }
- }();
- removeReplies(layerIdMap, replyXpathOffset, replyDomOffset);
- }
- break;
- default:
- console.error(`'${screenMode}' 에 대한 처리 방법이 아직 없습니다.`);
- break;
- }
- }
- function getElementByXpath(path) {
- return document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
- };
- function buildLayerIdMap() {
- // print_ZBlayer(name, homepage, mail, member_no, boardID, writer, traceID, traceType, isAdmin, isMember)
- var REGEX_ZB_LAYER_PRINT_FUNC = /print_ZBlayer\(['"](zbLayer[0-9]+)['"], ['"]()['"], ['"]()['"], ['"]([0-9]+)['"], .*\)/;
- const layerIdMap = {};
- Array.from(document.getElementsByTagName("script")).forEach(script => {
- const textNode = script.text.trim();
- const match = textNode.match(REGEX_ZB_LAYER_PRINT_FUNC);
- if (match) {
- textNode.split("\n").forEach(it => {
- const printArgs = it.match(REGEX_ZB_LAYER_PRINT_FUNC);
- layerIdMap[printArgs[1]] = printArgs[4];
- });
- }
- });
- return layerIdMap;
- }
- function removePosts(layerIdMap, postsCount, trOffset) {
- const quarantined = [];
- for (let i = 1; i <= postsCount; i++) {
- const trIndex = trOffset + i;
- const postRowXPath = `${XPATH_POSTS_TABLE}/tr[${trIndex}]`;
- const row = getElementByXpath(postRowXPath);
- const controller = getElementByXpath(`${postRowXPath}/td[1]/div/nobr/span/span`);
- if (isQuaratineTarget(layerIdMap, controller)) {
- quarantined.push(row);
- }
- }
- quarantined.forEach(it => it.remove());
- }
- function removeReplies(layerIdMap, replyXpathOffset, replyDomOffset) {
- const quarantined = [];
- const REGEX_REPLY_ID = /re[0-9]+/;
- const contents = getElementByXpath(XPATH_CONTENT_WITH_REPLIES).children;
- for (let i = 0; i < contents.length; i++) {
- const row = contents[i];
- const id = row.id;
- if (id == null || id.length === 0 || !id.match(REGEX_REPLY_ID)) {
- continue;
- }
- const domIndex = i - replyDomOffset;
- const replyIndex = replyXpathOffset + domIndex
- const controller = getElementByXpath(`/html/body/div[2]/div[2]/table[${replyIndex}]/tbody/tr[1]/td[2]/span/span[1]/b/span`);
- if (isQuaratineTarget(layerIdMap, controller)) {
- quarantined.push(row);
- }
- }
- quarantined.forEach(it => it.remove());
- }
- function isQuaratineTarget(layerIdMap, controller) {
- const [memberId, name] = getMemberInfo(layerIdMap, controller);
- if (memberId == null || userMatrix[memberId] == null) {
- return false;
- }
- console.debug(`게시물 숨김 대상: ${memberId} = '${name}', 메모: ${userMatrix[memberId]})`);
- return true;
- }
- function getMemberInfo(layerIdMap, zbActionControl) {
- // 컨트롤러 레이아웃 id인 #zbLayer[0-9]+ 패턴 찾기: Capturing group #2
- const REGEX_ZB_LAYER_INVOKE_FUNC = /ZB_layerAction\(['"](zbLayer[0-9]+)['"].*\)/;
- const action = zbActionControl.getAttribute("onmousedown");
- if (action == null) {
- return [];
- }
- const result = action.match(REGEX_ZB_LAYER_INVOKE_FUNC);
- if (result == null || result.length <= 1) {
- return [];
- }
- const zbLayerId = result[1];
- const memberId = layerIdMap[zbLayerId];
- if (memberId == null) {
- return [null, ""];
- } else {
- const name = zbActionControl.firstChild.textContent;
- return [memberId, name];
- }
- }
- // 프로그램 진입점
- main();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement