SE Preview on hover

Shows preview of the linked questions/answers on hover

当前为 2017-02-15 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name SE Preview on hover
  3. // @description Shows preview of the linked questions/answers on hover
  4. // @version 0.1.7
  5. // @author wOxxOm
  6. // @namespace wOxxOm.scripts
  7. // @license MIT License
  8. // @match *://*.stackoverflow.com/*
  9. // @match *://*.superuser.com/*
  10. // @match *://*.serverfault.com/*
  11. // @match *://*.askubuntu.com/*
  12. // @match *://*.stackapps.com/*
  13. // @match *://*.mathoverflow.net/*
  14. // @match *://*.stackexchange.com/*
  15. // @require https://greasyfork.org/scripts/12228/code/setMutationHandler.js
  16. // @require https://cdnjs.cloudflare.com/ajax/libs/lz-string/1.4.4/lz-string.min.js
  17. // @grant GM_addStyle
  18. // @grant GM_xmlhttpRequest
  19. // @connect stackoverflow.com
  20. // @connect superuser.com
  21. // @connect serverfault.com
  22. // @connect askubuntu.com
  23. // @connect stackapps.com
  24. // @connect mathoverflow.net
  25. // @connect stackexchange.com
  26. // @connect cdn.sstatic.net
  27. // @run-at document-end
  28. // @noframes
  29. // ==/UserScript==
  30.  
  31. /* jshint lastsemic:true, multistr:true, laxbreak:true, -W030, -W041, -W084 */
  32.  
  33. const PREVIEW_DELAY = 100;
  34. const CACHE_DURATION = 1 * 60 * 1000; // 1 minute for the recently active posts, scales up logarithmically
  35. const COLORS = {
  36. question: {
  37. backRGB: '80, 133, 195',
  38. fore: '#265184',
  39. },
  40. answer: {
  41. backRGB: '112, 195, 80',
  42. fore: '#3f7722',
  43. foreInv: 'white',
  44. },
  45. deleted: {
  46. backRGB: '181, 103, 103',
  47. fore: 'rgb(181, 103, 103)',
  48. foreInv: 'white',
  49. },
  50. };
  51.  
  52. let xhr;
  53. let preview = {
  54. frame: null,
  55. link: null,
  56. hover: {x:0, y:0},
  57. timer: 0,
  58. cacheCSS: {},
  59. stylesOverride: '',
  60. };
  61.  
  62. const rxPreviewable = getURLregexForMatchedSites();
  63. const thisPageUrls = getPageBaseUrls(location.href);
  64.  
  65. initStyles();
  66. initPolyfills();
  67. setMutationHandler('a', onLinkAdded, {processExisting: true});
  68. setTimeout(cleanupCache, 10000);
  69.  
  70. /**************************************************************/
  71.  
  72. function onLinkAdded(links) {
  73. for (let i = 0, link; (link = links[i++]); ) {
  74. if (isLinkPreviewable(link)) {
  75. link.removeAttribute('title');
  76. link.addEventListener('mouseover', onLinkHovered);
  77. }
  78. }
  79. }
  80.  
  81. function onLinkHovered(e) {
  82. if (e.ctrlKey || e.altKey || e.shiftKey || e.metaKey)
  83. return;
  84. preview.link = this;
  85. preview.link.addEventListener('mousemove', onLinkMouseMove);
  86. preview.link.addEventListener('mouseout', abortPreview);
  87. preview.link.addEventListener('mousedown', abortPreview);
  88. restartPreviewTimer(this);
  89. }
  90.  
  91. function onLinkMouseMove(e) {
  92. let stoppedMoving = Math.abs(preview.hover.x - e.clientX) < 2 &&
  93. Math.abs(preview.hover.y - e.clientY) < 2;
  94. if (!stoppedMoving)
  95. return;
  96. preview.hover.x = e.clientX;
  97. preview.hover.y = e.clientY;
  98. restartPreviewTimer(this);
  99. }
  100.  
  101. function restartPreviewTimer(link) {
  102. clearTimeout(preview.timer);
  103. preview.timer = setTimeout(() => {
  104. preview.timer = 0;
  105. link.removeEventListener('mousemove', onLinkMouseMove);
  106. if (link.matches(':hover'))
  107. downloadPreview(link.href);
  108. }, PREVIEW_DELAY);
  109. }
  110.  
  111. function abortPreview(e) {
  112. releaseLinkListeners(this);
  113. preview.timer = setTimeout(link => {
  114. if (link == preview.link && preview.frame && !preview.frame.matches(':hover')) {
  115. releaseLinkListeners(link);
  116. preview.frame.contentWindow.postMessage('SEpreviewHidden', '*');
  117. fadeOut(preview.frame);
  118. }
  119. }, PREVIEW_DELAY * 3, this);
  120. if (xhr)
  121. xhr.abort();
  122. }
  123.  
  124. function releaseLinkListeners(link) {
  125. link.removeEventListener('mousemove', onLinkMouseMove);
  126. link.removeEventListener('mouseout', abortPreview);
  127. link.removeEventListener('mousedown', abortPreview);
  128. clearTimeout(preview.timer);
  129. }
  130.  
  131. function fadeOut(element, transition) {
  132. if (transition) {
  133. element.style.transition = typeof transition == 'number' ? `opacity ${transition}s ease-in-out` : transition;
  134. return setTimeout(fadeOut, 0, element);
  135. }
  136. element.style.opacity = 0;
  137. element.addEventListener('transitionend', function remove() {
  138. element.removeEventListener('transitionend', remove);
  139. if (+element.style.opacity === 0)
  140. element.style.display = 'none';
  141. });
  142. }
  143.  
  144. function downloadPreview(url) {
  145. let cached = readCache(url);
  146. if (cached)
  147. showPreview(cached);
  148. else {
  149. xhr = GM_xmlhttpRequest({
  150. method: 'GET',
  151. url: httpsUrl(url),
  152. onload: r => {
  153. let html = r.responseText;
  154. let lastActivity = showPreview({finalUrl: r.finalUrl, html});
  155. let inactiveDays = Math.max(0, (Date.now() - lastActivity) / (24 * 3600 * 1000));
  156. let cacheDuration = CACHE_DURATION * Math.pow(Math.log(inactiveDays + 1) + 1, 2);
  157. writeCache({url, finalUrl: r.finalUrl, html, cacheDuration});
  158. },
  159. });
  160. }
  161. }
  162.  
  163. function showPreview({finalUrl, html, doc}) {
  164. doc = doc || new DOMParser().parseFromString(html, 'text/html');
  165. if (!doc || !doc.head) {
  166. error('no HEAD in the document received for', finalUrl);
  167. return;
  168. }
  169.  
  170. if (!$(doc, 'base'))
  171. doc.head.insertAdjacentHTML('afterbegin', `<base href="${finalUrl}">`);
  172.  
  173. const answerIdMatch = finalUrl.match(/questions\/.+?\/(\d+)/);
  174. const isQuestion = !answerIdMatch;
  175. const postId = answerIdMatch ? '#answer-' + answerIdMatch[1] : '#question';
  176. const post = $(doc, postId + ' .post-text');
  177. if (!post)
  178. return error('No parsable post found', doc);
  179. const isDeleted = post.closest('.deleted-answer');
  180. const title = $(doc, 'meta[property="og:title"]').content;
  181. const status = isQuestion && !$(post, '.question-status') && $(doc, '.question-status');
  182. const comments = $(doc, `${postId} .comments`);
  183. const commentsHidden = +$(comments, 'tbody').dataset.remainingCommentsCount;
  184. const commentsShowLink = commentsHidden && $(doc, `${postId} .js-show-link.comments-link`);
  185.  
  186. const lastActivity = +doc.body.getAttribute('SEpreview-lastActivity')
  187. || tryCatch(() => new Date($(doc, '.lastactivity-link').title).getTime())
  188. || Date.now();
  189. if (lastActivity)
  190. doc.body.setAttribute('SEpreview-lastActivity', lastActivity);
  191.  
  192. $$remove(doc, 'script');
  193.  
  194. // underline previewable links
  195. for (let link of $$(doc, 'a:not(.SEpreviewable)')) {
  196. if (rxPreviewable.test(link.href)) {
  197. link.removeAttribute('title');
  198. link.classList.add('SEpreviewable');
  199. }
  200. }
  201.  
  202. if (!preview.frame) {
  203. preview.frame = document.createElement('iframe');
  204. preview.frame.id = 'SEpreview';
  205. document.body.appendChild(preview.frame);
  206. }
  207.  
  208. preview.frame.setAttribute('SEpreviewType', isDeleted ? 'deleted' : isQuestion ? 'question' : 'answer');
  209. onFrameReady(preview.frame, addStyles);
  210. return lastActivity;
  211.  
  212. function addStyles() {
  213. const pvDoc = preview.frame.contentDocument;
  214. const SEpreviewStyles = $replaceOrCreate({
  215. id: 'SEpreviewStyles',
  216. tag: 'style', parent: pvDoc.head, className: 'SEpreviewReuse',
  217. innerHTML: preview.stylesOverride,
  218. });
  219.  
  220. $replaceOrCreate($$(doc, 'style, link[rel="stylesheet"]').map(e =>
  221. e.localName == 'style' ? {
  222. id: 'SEpreview' + e.innerHTML.replace(/\W+/g, '').length,
  223. tag: 'style', before: SEpreviewStyles, className: 'SEpreviewReuse',
  224. innerHTML: e.innerHTML,
  225. } : {
  226. id: e.href.replace(/\W+/g, ''),
  227. tag: 'link', before: SEpreviewStyles, className: 'SEpreviewReuse',
  228. href: e.href, rel: 'stylesheet',
  229. })
  230. );
  231.  
  232. onStyleSheetsReady([...$$(pvDoc, 'link[rel="stylesheet"]')], render);
  233. }
  234.  
  235. function render() {
  236. const finalUrlOfQuestion = getCacheableUrl(finalUrl);
  237. const pvDoc = preview.frame.contentDocument;
  238. pvDoc.body.setAttribute('SEpreviewType', preview.frame.getAttribute('SEpreviewType'));
  239.  
  240. $replaceOrCreate([{
  241. id: 'SEpreviewTitle',
  242. tag: 'a', parent: pvDoc.body, className: 'SEpreviewable',
  243. href: isQuestion ? finalUrl : finalUrlOfQuestion,
  244. textContent: title,
  245. }, {
  246. id: 'SEpreviewBody',
  247. tag: 'div', parent: pvDoc.body, className: isDeleted ? 'deleted-answer' : '',
  248. children: [post.parentElement, comments, commentsShowLink, status],
  249. }]);
  250.  
  251. const codeBlocks = $$(pvDoc, 'pre code');
  252. if (codeBlocks.length) {
  253. codeBlocks.forEach(e => e.parentElement.classList.add('prettyprint'));
  254. if (!preview.frame.contentWindow.StackExchange) {
  255. preview.frame.contentWindow.StackExchange = {};
  256. let script = $scriptIn(pvDoc.head);
  257. script.text = 'StackExchange = {}';
  258. script = $scriptIn(pvDoc.head);
  259. script.src = 'https://cdn.sstatic.net/Js/prettify-full.en.js';
  260. script.setAttribute('onload', 'prettyPrint()');
  261. } else
  262. $scriptIn(pvDoc.body).text = 'prettyPrint()';
  263. }
  264.  
  265. const answers = $$(doc, '.answer');
  266. if (answers.length > (isQuestion ? 0 : 1)) {
  267. $replaceOrCreate({
  268. id: 'SEpreviewAnswers',
  269. tag: 'div', parent: pvDoc.body,
  270. innerHTML: 'Answers:&nbsp;' + answers.map((e, index) => {
  271. const shortUrl = $(e, '.short-link').href.replace(/(\d+)\/\d+/, '$1');
  272. const extraClasses = (e.matches(postId) ? ' SEpreviewed' : '') +
  273. (e.matches('.deleted-answer') ? ' deleted-answer' : '');
  274. return `<a href="${shortUrl}"
  275. SEpreviewFullUrl="${finalUrlOfQuestion + '/' + shortUrl.match(/\/(\d+)/)[1]}"
  276. title="${$text(e, '.user-details a') + ' (rep ' + $text(e, '.reputation-score') + ')\n' +
  277. $text(e, '.user-action-time') +
  278. $text(e, '.vote-count-post').replace(/-?\d+/, s =>
  279. s == '0' ? '' : '\n' + s + ' vote' + (+s > 1 ? 's' : ''))}"
  280. class="SEpreviewable${extraClasses}"
  281. >${index + 1}</a>`;
  282. }).join(''),
  283. });
  284. } else
  285. $$remove(pvDoc, '#SEpreviewAnswers');
  286.  
  287. [...$$(pvDoc.head, 'style, link'), ...$$(pvDoc.body, 'script')].forEach(e => {
  288. if (e.classList.contains('SEpreviewReuse'))
  289. e.classList.remove('SEpreviewReuse');
  290. else
  291. e.remove();
  292. });
  293.  
  294. pvDoc.onmouseover = retainMainScrollPos;
  295. pvDoc.onclick = interceptLinks;
  296. preview.frame.contentWindow.onmessage = e => {
  297. if (e.data == 'SEpreviewHidden') {
  298. preview.frame.contentWindow.onmessage = null;
  299. pvDoc.onmouseover = null;
  300. pvDoc.onclick = null;
  301. }
  302. };
  303.  
  304. $(pvDoc, '#SEpreviewBody').scrollTop = 0;
  305. preview.frame.style.opacity = 1;
  306. preview.frame.style.display = '';
  307. }
  308.  
  309. function interceptLinks(e) {
  310. const link = e.target.closest('a');
  311. if (!link)
  312. return;
  313. if (link.matches('.js-show-link.comments-link')) {
  314. fadeOut(link, 0.5);
  315. downloadComments();
  316. }
  317. else if (e.button || e.ctrlKey || e.altKey || e.shiftKey || e.metaKey || !link.matches('.SEpreviewable'))
  318. return (link.target = '_blank');
  319. else if (link.matches('#SEpreviewAnswers a, a#SEpreviewTitle'))
  320. showPreview({
  321. finalUrl: link.getAttribute('SEpreviewFullUrl') || link.href,
  322. doc
  323. });
  324. else
  325. downloadPreview(link.getAttribute('SEpreviewFullUrl') || link.href);
  326. e.preventDefault();
  327. }
  328.  
  329. function downloadComments() {
  330. GM_xmlhttpRequest({
  331. method: 'GET',
  332. url: new URL(finalUrl).origin + '/posts/' + comments.id.match(/\d+/)[0] + '/comments',
  333. onload: r => showComments(r.responseText),
  334. });
  335. }
  336.  
  337. function showComments(html) {
  338. let tbody = $(preview.frame.contentDocument, `#${comments.id} tbody`);
  339. let oldIds = new Set([...tbody.rows].map(e => e.id));
  340. tbody.innerHTML = html;
  341. for (let tr of tbody.rows)
  342. if (!oldIds.has(tr.id))
  343. tr.classList.add('new-comment-highlight');
  344. }
  345. }
  346.  
  347. function retainMainScrollPos(e) {
  348. let scrollPos = {x:scrollX, y:scrollY};
  349. document.addEventListener('scroll', preventScroll);
  350. document.addEventListener('mouseover', releaseScrollLock);
  351.  
  352. function preventScroll(e) {
  353. scrollTo(scrollPos.x, scrollPos.y);
  354. log('prevented main page scroll');
  355. }
  356.  
  357. function releaseScrollLock(e) {
  358. document.removeEventListener('mouseout', releaseScrollLock);
  359. document.removeEventListener('scroll', preventScroll);
  360. }
  361. }
  362.  
  363. function getCacheableUrl(url) {
  364. // strips querys and hashes and anything after the main part https://site/questions/####/title/
  365. return url
  366. .replace(/(\/q(?:uestions)?\/\d+\/[^\/]+).*/, '$1')
  367. .replace(/(\/a(?:nswers)?\/\d+).*/, '$1')
  368. .replace(/[?#].*$/, '');
  369. }
  370.  
  371. function readCache(url) {
  372. keyUrl = getCacheableUrl(url);
  373. const meta = (localStorage[keyUrl] || '').split('\t');
  374. const expired = +meta[0] < Date.now();
  375. const finalUrl = meta[1] || url;
  376. const keyFinalUrl = meta[1] ? getCacheableUrl(finalUrl) : keyUrl;
  377. return !expired && {
  378. finalUrl,
  379. html: LZString.decompressFromUTF16(localStorage[keyFinalUrl + '\thtml']),
  380. };
  381. }
  382.  
  383. function writeCache({url, finalUrl, html, cacheDuration = CACHE_DURATION, cleanupRetry}) {
  384. // keyUrl=expires
  385. // redirected keyUrl=expires+finalUrl, and an additional entry keyFinalUrl=expires is created
  386. // keyFinalUrl\thtml=html
  387. cacheDuration = Math.max(CACHE_DURATION, Math.min(0xDEADBEEF, Math.floor(cacheDuration)));
  388. finalUrl = finalUrl.replace(/[?#].*/, '');
  389. const keyUrl = getCacheableUrl(url);
  390. const keyFinalUrl = getCacheableUrl(finalUrl);
  391. const expires = Date.now() + cacheDuration;
  392. if (!tryCatch(() => localStorage[keyFinalUrl + '\thtml'] = LZString.compressToUTF16(html))) {
  393. if (cleanupRetry)
  394. return error('localStorage write error');
  395. cleanupCache({aggressive: true});
  396. setIimeout(writeCache, 0, {url, finalUrl, html, cacheDuration, cleanupRetry: true});
  397. }
  398. localStorage[keyFinalUrl] = expires;
  399. if (keyUrl != keyFinalUrl)
  400. localStorage[keyUrl] = expires + '\t' + finalUrl;
  401. setTimeout(() => {
  402. [keyUrl, keyFinalUrl, keyFinalUrl + '\thtml'].forEach(e => localStorage.removeItem(e));
  403. }, cacheDuration + 1000);
  404. }
  405.  
  406. function cleanupCache({aggressive = false} = {}) {
  407. Object.keys(localStorage).forEach(k => {
  408. if (k.match(/^https?:\/\/[^\t]+$/)) {
  409. let meta = (localStorage[k] || '').split('\t');
  410. if (+meta[0] > Date.now() && !aggressive)
  411. return;
  412. if (meta[1])
  413. localStorage.removeItem(meta[1]);
  414. localStorage.removeItem(`${meta[1] || k}\thtml`);
  415. localStorage.removeItem(k);
  416. }
  417. });
  418. }
  419.  
  420. function onFrameReady(frame, callback, ...args) {
  421. if (frame.contentDocument.readyState == 'complete')
  422. return callback.call(frame, ...args);
  423. else
  424. frame.addEventListener('load', function onLoad() {
  425. frame.removeEventListener('load', onLoad);
  426. callback.call(frame, ...args);
  427. });
  428. }
  429.  
  430. function onStyleSheetsReady(linkElements, callback, ...args) {
  431. if (linkElements.every(e => e.sheet && e.sheet.href == e.href))
  432. return callback(...args);
  433. else
  434. setTimeout(onStyleSheetsReady, 0, linkElements, callback, ...args);
  435. }
  436.  
  437. function getURLregexForMatchedSites() {
  438. return new RegExp('https?://(\\w*\\.)*(' + GM_info.script.matches.map(m =>
  439. m.match(/^.*?\/\/\W*(\w.*?)\//)[1].replace(/\./g, '\\.')
  440. ).join('|') + ')/(questions|q|a)/\\d+');
  441. }
  442.  
  443. function isLinkPreviewable(link) {
  444. const inPreview = link.ownerDocument != document;
  445. if (!rxPreviewable.test(link.href) || link.matches('.short-link'))
  446. return false;
  447. const pageUrls = inPreview ? getPageBaseUrls(preview.link.href) : thisPageUrls;
  448. const url = httpsUrl(link.href);
  449. return !url.startsWith(pageUrls.base) &&
  450. !url.startsWith(pageUrls.short);
  451. }
  452.  
  453. function getPageBaseUrls(url) {
  454. const base = httpsUrl((url.match(rxPreviewable) || [])[0]);
  455. return base ? {
  456. base,
  457. short: base.replace('/questions/', '/q/'),
  458. } : {};
  459. }
  460.  
  461. function httpsUrl(url) {
  462. return (url || '').replace(/^http:/, 'https:');
  463. }
  464.  
  465. function $(node__optional, selector) {
  466. return (node__optional || document).querySelector(selector || node__optional);
  467. }
  468.  
  469. function $$(node__optional, selector) {
  470. return (node__optional || document).querySelectorAll(selector || node__optional);
  471. }
  472.  
  473. function $text(node__optional, selector) {
  474. const e = $(node__optional, selector);
  475. return e ? e.textContent.trim() : '';
  476. }
  477.  
  478. function $$remove(node__optional, selector) {
  479. (node__optional || document).querySelectorAll(selector || node__optional)
  480. .forEach(e => e.remove());
  481. }
  482.  
  483. function $appendTo(newParent, elements) {
  484. const doc = newParent.ownerDocument;
  485. for (let e of elements)
  486. if (e)
  487. newParent.appendChild(e.ownerDocument == doc ? e : doc.importNode(e, true));
  488. }
  489.  
  490. function $replaceOrCreate(options) {
  491. if (options.length && typeof options[0] == 'object')
  492. return [].map.call(options, $replaceOrCreate);
  493. const doc = (options.parent || options.before).ownerDocument;
  494. const el = doc.getElementById(options.id) || doc.createElement(options.tag);
  495. for (let key of Object.keys(options)) {
  496. switch (key) {
  497. case 'tag':
  498. case 'parent':
  499. case 'before':
  500. break;
  501. case 'children':
  502. if (el.children.length)
  503. el.innerHTML = '';
  504. $appendTo(el, options[key]);
  505. break;
  506. default:
  507. const value = options[key];
  508. if (key in el && el[key] != value)
  509. el[key] = value;
  510. }
  511. }
  512. if (!el.parentElement)
  513. (options.parent || options.before.parentElement).insertBefore(el, options.before);
  514. return el;
  515. }
  516.  
  517. function $scriptIn(element) {
  518. return element.appendChild(element.ownerDocument.createElement('script'));
  519. }
  520.  
  521. function log(...args) {
  522. console.log(GM_info.script.name, ...args);
  523. }
  524.  
  525. function error(...args) {
  526. console.error(GM_info.script.name, ...args);
  527. }
  528.  
  529. function tryCatch(fn) {
  530. try { return fn() }
  531. catch(e) {}
  532. }
  533.  
  534. function initPolyfills() {
  535. for (let method of ['forEach', 'filter', 'map', Symbol.iterator])
  536. if (!NodeList.prototype[method])
  537. NodeList.prototype[method] = Array.prototype[method];
  538. }
  539.  
  540. function initStyles() {
  541. GM_addStyle(`
  542. #SEpreview {
  543. all: unset;
  544. box-sizing: content-box;
  545. width: 720px; /* 660px + 30px + 30px */
  546. height: 33%;
  547. min-height: 200px;
  548. position: fixed;
  549. opacity: 0;
  550. transition: opacity .5s cubic-bezier(.88,.02,.92,.66);
  551. right: 0;
  552. bottom: 0;
  553. padding: 0;
  554. margin: 0;
  555. background: white;
  556. box-shadow: 0 0 100px rgba(0,0,0,0.5);
  557. z-index: 999999;
  558. border: 8px solid rgb(${COLORS.question.backRGB});
  559. }
  560. #SEpreview[SEpreviewType="answer"] {
  561. border-color: rgb(${COLORS.answer.backRGB});
  562. }
  563. #SEpreview[SEpreviewType="deleted"] {
  564. border-color: rgba(${COLORS.deleted.backRGB}, 0.65);
  565. }
  566. `);
  567.  
  568. preview.stylesOverride = `
  569. body, html {
  570. min-width: unset!important;
  571. box-shadow: none!important;
  572. padding: 0!important;
  573. margin: 0!important;
  574. }
  575. html, body {
  576. background: unset!important;;
  577. }
  578. body {
  579. display: flex;
  580. flex-direction: column;
  581. height: 100vh;
  582. }
  583. a.SEpreviewable {
  584. text-decoration: underline !important;
  585. }
  586. #SEpreviewTitle {
  587. all: unset;
  588. display: block;
  589. padding: 20px 30px;
  590. font-weight: bold;
  591. font-size: 20px;
  592. line-height: 1.3;
  593. background-color: rgba(${COLORS.question.backRGB}, 0.37);
  594. color: ${COLORS.question.fore};
  595. cursor: pointer;
  596. }
  597. #SEpreviewTitle:hover {
  598. text-decoration: underline;
  599. }
  600. #SEpreviewBody {
  601. padding: 30px!important;
  602. overflow: auto;
  603. flex-grow: 2;
  604. }
  605. #SEpreviewBody .post-menu {
  606. display: none!important;
  607. }
  608. #SEpreviewBody > .question-status {
  609. margin: -10px -30px -30px;
  610. padding-left: 30px;
  611. }
  612. #SEpreviewBody > .question-status h2 {
  613. font-weight: normal;
  614. }
  615.  
  616. #SEpreviewBody::-webkit-scrollbar {
  617. background-color: rgba(${COLORS.question.backRGB}, 0.1);
  618. }
  619. #SEpreviewBody::-webkit-scrollbar-thumb {
  620. background-color: rgba(${COLORS.question.backRGB}, 0.2);
  621. }
  622. #SEpreviewBody::-webkit-scrollbar-thumb:hover {
  623. background-color: rgba(${COLORS.question.backRGB}, 0.3);
  624. }
  625. #SEpreviewBody::-webkit-scrollbar-thumb:active {
  626. background-color: rgba(${COLORS.question.backRGB}, 0.75);
  627. }
  628. /* answer */
  629. body[SEpreviewType="answer"] #SEpreviewTitle {
  630. background-color: rgba(${COLORS.answer.backRGB}, 0.37);
  631. color: ${COLORS.answer.fore};
  632. }
  633. body[SEpreviewType="answer"] #SEpreviewBody::-webkit-scrollbar {
  634. background-color: rgba(${COLORS.answer.backRGB}, 0.1);
  635. }
  636. body[SEpreviewType="answer"] #SEpreviewBody::-webkit-scrollbar-thumb {
  637. background-color: rgba(${COLORS.answer.backRGB}, 0.2);
  638. }
  639. body[SEpreviewType="answer"] #SEpreviewBody::-webkit-scrollbar-thumb:hover {
  640. background-color: rgba(${COLORS.answer.backRGB}, 0.3);
  641. }
  642. body[SEpreviewType="answer"] #SEpreviewBody::-webkit-scrollbar-thumb:active {
  643. background-color: rgba(${COLORS.answer.backRGB}, 0.75);
  644. }
  645. /* deleted */
  646. body[SEpreviewType="deleted"] #SEpreviewTitle {
  647. background-color: rgba(${COLORS.deleted.backRGB}, 0.37);
  648. color: ${COLORS.deleted.fore};
  649. }
  650. body[SEpreviewType="deleted"] #SEpreviewBody::-webkit-scrollbar {
  651. background-color: rgba(${COLORS.deleted.backRGB}, 0.1);
  652. }
  653. body[SEpreviewType="deleted"] #SEpreviewBody::-webkit-scrollbar-thumb {
  654. background-color: rgba(${COLORS.deleted.backRGB}, 0.2);
  655. }
  656. body[SEpreviewType="deleted"] #SEpreviewBody::-webkit-scrollbar-thumb:hover {
  657. background-color: rgba(${COLORS.deleted.backRGB}, 0.3);
  658. }
  659. body[SEpreviewType="deleted"] #SEpreviewBody::-webkit-scrollbar-thumb:active {
  660. background-color: rgba(${COLORS.deleted.backRGB}, 0.75);
  661. }
  662. /********/
  663. #SEpreviewAnswers {
  664. all: unset;
  665. display: block;
  666. padding: 10px 30px;
  667. font-weight: bold;
  668. font-size: 20px;
  669. line-height: 1.3;
  670. border-top: 4px solid rgba(${COLORS.answer.backRGB}, 0.37);
  671. background-color: rgba(${COLORS.answer.backRGB}, 0.37);
  672. color: ${COLORS.answer.fore};
  673. word-break: break-word;
  674. }
  675. #SEpreviewAnswers a {
  676. color: ${COLORS.answer.fore};
  677. padding: .25ex .75ex;
  678. text-decoration: none;
  679. }
  680. #SEpreviewAnswers a.deleted-answer {
  681. color: ${COLORS.deleted.fore};
  682. background: transparent;
  683. }
  684. #SEpreviewAnswers a:hover:not(.SEpreviewed) {
  685. text-decoration: underline;
  686. }
  687. #SEpreviewAnswers a.SEpreviewed {
  688. background-color: ${COLORS.answer.fore};
  689. color: ${COLORS.answer.foreInv};
  690. }
  691. /* deleted */
  692. body[SEpreviewType="deleted"] #SEpreviewAnswers {
  693. border-top-color: rgba(${COLORS.deleted.backRGB}, 0.37);
  694. background-color: rgba(${COLORS.deleted.backRGB}, 0.37);
  695. color: ${COLORS.deleted.fore};
  696. }
  697. body[SEpreviewType="deleted"] #SEpreviewAnswers a.SEpreviewed {
  698. background-color: ${COLORS.deleted.fore};
  699. color: ${COLORS.deleted.foreInv};
  700. }
  701. /********/
  702. .comments .new-comment-highlight {
  703. -webkit-animation: highlight 9s cubic-bezier(0,.8,.37,.88);
  704. -moz-animation: highlight 9s cubic-bezier(0,.8,.37,.88);
  705. animation: highlight 9s cubic-bezier(0,.8,.37,.88);
  706. }
  707.  
  708. @-webkit-keyframes highlight {
  709. from {background-color: #ffcf78}
  710. to {background-color: none}
  711. }
  712. `;
  713. }