// ==UserScript==
// @name Lofter 网页版显示划线评论
// @license GPLv3
// @namespace http://tampermonkey.net/
// @version 0.4
// @description 在 Lofter 网页版显示划线评论
// @author SrakhiuMeow
// @match *://*.lofter.com/post*
// @match *://*.lofter.com/comment*
// @grant none
// @require https://unpkg.com/ajax-hook@3.0/dist/ajaxhook.min.js
// @run-at document-start
// @downloadURL https://update.greasyfork.icu/scripts/530884/Lofter%20%E7%BD%91%E9%A1%B5%E7%89%88%E6%98%BE%E7%A4%BA%E5%88%92%E7%BA%BF%E8%AF%84%E8%AE%BA.user.js
// @updateURL https://update.greasyfork.icu/scripts/530884/Lofter%20%E7%BD%91%E9%A1%B5%E7%89%88%E6%98%BE%E7%A4%BA%E5%88%92%E7%BA%BF%E8%AF%84%E8%AE%BA.meta.js
// ==/UserScript==
(function() {
'use strict';
// 共用变量
let comments = [];
let resp = null;
// 解析评论数据
function parse(data) {
const lines = data.trim().split('\n');
const result = [];
const lastLine = lines.pop();
// console.log("lastLine", lastLine);
if (lastLine === 'null') {
return null;
}
const validIndex = lastLine.match(/\[(.*?)\]/g)[0].slice(1, -1).split(',');
const iframe = document.createElement('iframe');
iframe.style.display = 'none';
document.body.appendChild(iframe);
iframe.contentWindow.eval(lines.join('\n'));
for (const idx of validIndex) {
result.push(iframe.contentWindow[idx]);
}
return result;
}
// 显示评论
// 暂未实现显示回复评论的评论
function displayComments(comments) {
for (const comment of comments) {
if ('pid' in comment && comment.pid !== 'null') {
// console.log(comment);
if (comment.pid === null) {
continue;
}
else if ('pid' in comment) {
const pElement = document.getElementById(comment.pid);
let button = document.getElementById(comment.pid + 'button');
if (button === null) {
// 创建新评论显示区域
button = document.createElement('button');
button.textContent = '1';
button.id = comment.pid + 'button';
pElement.appendChild(button);
const div = document.createElement('div');
const ol = document.createElement('ol');
ol.className = 'notes';
ol.id = comment.pid + 'ol';
div.appendChild(ol);
const li = document.createElement('li');
li.className = 'note like';
li.innerHTML = `
${comment.publisherMainBlogInfo.blogNickName} : ${comment.content}