Last active
June 26, 2019 01:44
-
-
Save KaKi87/9fadc869f11aebd8d3f71b01baf06f0f to your computer and use it in GitHub Desktop.
XDA Forums userscript : show threads meta in threads list
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name XDA Forums - Threads meta | |
// @namespace https://kaki87.net/ | |
// @version 1.0 | |
// @match https://forum.xda-developers.com/* | |
// @author KaKi87 | |
// @license MIT | |
// ==/UserScript== | |
window.addEventListener('DOMContentLoaded', () => { | |
if(!document.querySelector('.thread-listing')) return; | |
const getThreadMeta = link => new Promise(resolve => $.get(link, data => { | |
const zip = (keys, values) => Object.assign(...keys.map((k, i) => ({ [k]: values[i] }))) | |
const thread = new DOMParser().parseFromString(data, 'text/html'); | |
resolve({ | |
created: zip(['date', 'time'], | |
thread.querySelector('#thread-header-meta') | |
.textContent.trim().split('\n')[0].split(' on ')[1].split(', ')), | |
...(thread.querySelector('.postbit-edited') ? { | |
edited: zip(['author', 'date', 'time'], thread.querySelector('.postbit-edited').textContent.match(/Last edited by (.+); (.+) at (.+)\./).slice(1)) | |
} : {}) | |
}); | |
})); | |
(async() => { | |
const threads = [...document.querySelectorAll('.thread-row')].map(el => ({ | |
link: el.querySelector('.threadTitle').href, | |
author: el.querySelector('div.smallfont a').textContent, | |
subtitle: el.querySelector('div.smallfont') | |
})); | |
for(let i = 0; i < threads.length; i++){ | |
const | |
thread = threads[i], | |
meta = await getThreadMeta(thread.link); | |
thread.subtitle.innerHTML += `, created on ${meta.created.date} ${meta.created.time}${meta.edited ? `, edited on ${meta.edited.date} ${meta.edited.time} ${(thread.author !== meta.edited.author) ? `by ${meta.edited.author}` : ''}` : ''}`; | |
} | |
})(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
reserved