Notatkowator 2020

Szybki podgląd notek

当前为 2021-12-31 提交的版本,查看 最新版本

// @ts-ignore
const VSCodeLMDate = "2021/12/31 12:35:39";

// @ts-ignore
const diffTime = Math.abs(Date.now() - new Date(VSCodeLMDate).getTime())/1000;
// console.log(VSCodeLMDate, `${Math.floor(diffTime)} secs ago`);

// ==UserScript==
// @name        Notatkowator 2020
// @description Szybki podgląd notek
// @version     2.2
// @author      piokom123, look997
// @include     https://www.wykop.pl/*
// @homepageURL https://www.wykop.pl/ludzie/addons/look997/
// @namespace	  https://www.wykop.pl/ludzie/addons/look997/
// @grant       GM_xmlhttpRequest
// @require     https://gf.qytechs.cn/scripts/437595-wykopobserve/code/WykopObserve.js?version=1002287
// @run-at      document-end
// @resource    metadata https://gf.qytechs.cn/scripts/437598-notatkowator-2020/code/Notatkowator%202020.user.js
// @icon        https://www.google.com/s2/favicons?domain=wykop.pl
// @icon64      https://www.google.com/s2/favicons?domain=wykop.pl
// ==/UserScript==
// Ukłony dla @parasolki za nadanie dodatkowi tej boskiej nazwy ;)

(async function () {
	
	/**
	 * Parses user notes list HTML and returns as object
	 */
	function parseNotes(data) {
		const userNotes = {};
		
		(new DOMParser()).parseFromString(data, "text/html").querySelectorAll('#notesList li p').forEach((item,index)=>{
			
			const abEl = item.querySelector('a b');
			if (!(abEl instanceof HTMLElement)) { return false; }
			userNotes[abEl.textContent] = parseNote(item.innerHTML);
		})
		return userNotes;
	}
	
	/**
	 * Parses HTML of one note
	 */
	function parseNote(content) {
		var parsedNote = '';
		var match = content.split('</b></a>');
		match = match[1].trim();
		
		if (match.indexOf('|') === -1) {
			parsedNote = match;
		} else {
			match = match.split('|');
			parsedNote = match[0];
		}
		
		parsedNote = activateLinks(parsedNote);
		
		return parsedNote;
	}
	
	function activateLinks(content) {
		if (content.indexOf('http://') !== -1 || content.indexOf('https://') !== -1) {
			content = content.replace(/(https?:\/\/([^\s]+))/g, '<a href="$1" target="_blank">$1</a>');
		}
		
		return content;
	}
	
	
	function fetchText (url) {
		return new Promise((resolve,reject)=>{
			// @ts-ignore
			GM_xmlhttpRequest({
				method:"GET",
				url,
				//responseType: "json",
				onload: function(response) {
					resolve(response.responseText);
				},
				onerror: function(error) {
					reject(error);
				}
			});
		});
	}
	
	
	const saveStorage = (storageName, ob)=>{
		localStorage.setItem(storageName, JSON.stringify(ob));
	};
	
	
	// INIT Start
	
	const storageName = "userNotes";
	
	let userNotes = JSON.parse( localStorage.getItem(storageName) || '{}' );
	
	// @ts-ignore
	const {refresh} = await wykopObserve(
		[
			// @ts-ignore
			filterGroups.mikroblogLinkWpisGlownaTagMojCommentOrSubComment,
			// @ts-ignore
			filterGroups.ludziePageCommentOrSubComment
		],
		function ({profileEl, liEl, contentEl}, {place, isFirstTime, nick, authorSex}) {
			
			const authorEl = liEl.querySelector(".author");
			
			if (typeof userNotes[nick] === 'undefined') { return false; }
			const content = `| ${userNotes[nick]}`;
			const noteEl = liEl.querySelector(".note2020");
			if (noteEl) {
				noteEl.remove();
				const spanEl = document.createElement("span");
				spanEl.innerHTML = `<span class="note2020 notesFor_${nick}" style="padding-right: 55px; white-space: normal !important;">${content}</span>`;
				authorEl.append(spanEl.firstElementChild);
			} else {
				const spanEl = document.createElement("span");
				spanEl.innerHTML = `<span class="note2020 notesFor_${nick}" style="padding-right: 55px; white-space: normal !important;">${content}</span>`;
				authorEl.append(spanEl.firstElementChild);
			}
			
	}, {once:true});
	
	userNotes = parseNotes(await fetchText('https://www.wykop.pl/moj/notatki-o-uzytkownikach/'));
	saveStorage(storageName, userNotes);
	refresh();
	// INIT End
	
	})()
	

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址