xfdyd / -

博客
1 stars 0 forks source link

油猴脚本:自动展开全文(永久 beta 版) #1733

Open xfdyd opened 3 weeks ago

xfdyd commented 3 weeks ago

// ==UserScript== // @name 自动展开全文(永久 beta 版) // @namespace Expand the article for meow. // @match :/// // @grant GM_info // @grant GM_addStyle // @grant GM_getValue // @grant GM_setValue // @grant GM_deleteValue // @grant GM_registerMenuCommand // @grant GM_unregisterMenuCommand // @grant GM_openInTab // @run-at document-end // @version 1.2.0 // @supportURL https://docs.qq.com/form/page/DYVFEd3ZaQm5pZ1ZR // @homepageURL https://script.izyx.xyz/expand-the-article/ // @icon https://i.v2ex.co/2xpojai3s.png // @require https://greasyfork.org/scripts/408776-dms-userscripts-toolkit/code/DMS-UserScripts-Toolkit.js?version=840920 // @inject-into content // @noframes // @author 稻米鼠 // @created 2020-07-24 07:04:35 // @updated 2020-09-05 13:48:34 // @description 自动展开全文的 beta 版,大概永远不会正式。使用前请务必认真阅读发布页说明,安装即表示知悉、理解并同意说明中全部内容。默认不开启任何功能,请在脚本菜单中切换功能(设置只针对当前网站)。 // ==/UserScript== const expand_article_main_function = function(){ // if(!GM_getValue('notice_mark') || GM_getValue('notice_mark')!== '1.0.0'){ // if(confirm(【自动展开全文 beta】用法变更提示: // 1、付费后可获得内部版本,解锁更多功能; // 2、未付费用户视为盗版,不提供任何保障,也不保证可以正常使用; // 3、希望你认真读懂后再点击确认,【确认即代表已认真阅读,并理解,并同意所有内容】; // 4、默认适配所有网站,但不启用任何功能,就是默认啥都不会做滴~; // 5、在需要展开的网站下,通过脚本菜单开启相应功能。(悄悄告诉你,再点一下可以关闭哦~; // 6、由于一些原因,切换设置后页面会刷新。应该没人频繁切换吧,所以问题不大。)){ // GM_setValue('notice_mark', '1.0.0') // } // } const DMSTookit = new DMS_UserScripts.Toolkit({ GM_info, GM_addStyle, GM_getValue, GM_setValue, GM_deleteValue, GM_registerMenuCommand, GM_unregisterMenuCommand, GMopenInTab, }) const ruleName = 'rule'+window.location.hostname const options = DMSTookit.proxyDataAuto(ruleName, { expand_article: false, super_expand : false, remove_pop : false, include_home : false, }) DMSTookit.menuToggle(options, 'expand_article', '🍏自动展开启用中(仅本站)', '🍎自动展开禁用中(仅本站)', false, state=>{ if(state && window.location.pathname === '/' ){ options.include_home = true } window.location.reload(1) }) // DMSTookit.menuLink('2、🍎超级展开禁用中(仅付费用户)', 'https://script.izyx.xyz/expand-the-article/') // DMSTookit.menuLink('3、🍎去除遮挡禁用中(仅付费用户)', 'https://script.izyx.xyz/expand-the-article/') // DMSTookit.menuLink('4、🐹更多脚本', 'https://script.izyx.xyz/') if (!options.expand_article && !options.super_expand && !options.remove_pop) { if (GM_getValue(ruleName)){ GM_deleteValue(ruleName) }else if(window.localStorage.getItem(ruleName)){ window.localStorage.removeItem(ruleName) } return } if(window.location.pathname === '/' && !options.include_home) return const passagesMinCount = 3 const contentMinCount = 80 const expandButtonMaxChildren = 10 DMSTookit.addStyle( .expand-the-article-no-limit { max-height: none !important; height: auto !important; } .expand-the-article-display-none { display: none !important; } .expand-the-article-no-linear-gradient { -webkit-mask: none !important; } ) const elFilter = (el, is_rollback=false)=>{ try { if(!el) return false const excludeTags = [ 'abbr', 'applet', 'area', 'audio', 'b', 'base', 'bdi', 'bdo', 'body', 'br', 'canvas', 'caption', 'cite', 'code', 'col', 'colgroup', 'data', 'datalist', 'del', 'details', 'dfn', 'dialog', 'em', 'embed', 'fieldset', 'form', 'g', 'head', 'html', 'i', 'img', 'input', 'ins', 'kbd', 'label', 'legend', 'link', 'map', 'mark', 'marquee', 'menu', 'menuitem', 'meta', 'meter', 'noscript', 'optgroup', 'option', 'output', 'param', 'picture', 'pre', 'progress', 'q', 'rb', 'rp', 'rt', 'rtc', 'ruby', 's', 'samp', 'script', 'select', 'small', 'source', 'span', 'strong', 'style', 'sub', 'summary', 'sup', 'svg', 'table', 'tbody', 'td', 'textarea', 'tfoot', 'th', 'thead', 'time', 'title', 'tr', 'track', 'tt', 'u', 'var', 'video', 'wbr', ]; if(excludeTags.indexOf(el.tagName.toLowerCase()) !== -1){ return false } if(is_rollback){ if ( el.querySelectorAll('p, br, h1, h2, h3, h4, h5, h6').length >= passagesMinCount ) return true; }else{ let passages = 0 const children = el.children for(let i=0; i<children.length; i++){ if(/^(p|br|h1|h2|h3|h4|h5|h6)$/i.test(children[i].tagName)){ passages++ } } if(passages >= passagesMinCount){ return true } } if(el.innerText && el.innerText.length >= contentMinCount){ return true } } catch (error) {} return 0 } const removeMask = el=>{ if(elFilter(el) !== false){ const elStyle = window.getComputedStyle(el) if(/linear-gradient/i.test(elStyle.webkitMaskImage)){ el.classList.add('expand-the-article-no-linear-gradient') } } } const removeReadMoreButton = (el)=>{ for(const e of el.children){ const eStyle = window.getComputedStyle(e) if ( (/^(absolute)$/i.test(eStyle.position) || /^-\d/i.test(eStyle.marginTop)) && e.innerText.length < 100 && e.querySelectorAll('').length < expandButtonMaxChildren && e.querySelectorAll( 'html, head, meta, link, body, article, aside, footer, header, main, nav, section, audio, video, track, embed, iframe, style, script, input, textarea' ).length === 0 ) { e.classList.add('expand-the-article-display-none'); } else { removeMask(e); } } } const removeHeightLimit = el=>{ if(el.classList.contains('expand-the-article-no-limit')) return const elStyle = window.getComputedStyle(el) if ( elStyle.maxHeight !== 'none' || (elStyle.height !== 'auto' && elStyle.overflowY === 'hidden') ) { el.classList.add('expand-the-article-no-limit'); } removeReadMoreButton(el) } const expandAllEl = ()=>{ document.querySelectorAll('*').forEach((el)=>{ if(elFilter(el)) removeHeightLimit(el) }) } if(options.expand_article){ expandAllEl() window.addEventListener('load', function(){ expandAllEl() }) } } expand_article_main_function()

xfdyd commented 3 weeks ago

修改自用。