') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); })(); GitHub - AideLua/AndroLuaResGetter: Easy access to resource data in AndroLua+ · GitHub
Skip to content

Repository files navigation

AndroLua+ Res Getter

licenseGitee 发行版

Gitee 仓库Github 仓库

介绍

在 AndroLua+ 中很方便地获取资源数据

软件架构

  • lua/res.lua: res 模块

安装教程

  1. 复制 res.lua你的工程/lua
  2. main.lua 内导入 import 模块: require "import"
  3. 导入 res 模块: import "res"

名词说明

  • ResGetterHolder: 也就是 res
  • ResGetterTypeHolder: 也就是 res.xxx ,持有具体的资源类型,比如 color
  • ResGetterAttrHolder: 也就是 res.xxx.attr ,只是声明接下来获取的资源内容要从主题中获取

使用说明

访问规则:res.<类型>[.attr].<名称>

使用 res.xxx 使用全局变量 R 内容,一般为 com.androlua.R

如果您使用 Gradle 构建应用,可以先添加 R=luajava.bindClass(activity.getPackageName()..".R") 使用主模块中的 <包名>.R

使用 android.res.xxx 则会指定为全局变量 android.R 的 R 类,一般为 android.R

您也可以使用 res(id).xxx 指定使用的主题 ID,使用 res(rClass).xxx 指定使用的 R 类(v1.0 (alpha4)+)

注意:

  1. 部分资源在获取后会缓存,您可能需要执行 res:clearCache() 来清除这个 ResGetterHolder 下的所有缓存
  2. 图片资源等默认不会缓存。您可以 res.setSupportCacheGetterMap(getterText,state) 来启用这些资源的缓存
  3. res 模块暂时只支持主 ResGetterHolder 通过 res:clearCache() 调用,其他的请使用 res.clearCache(otherRes) 调用各种方法

示例(以 AndroLuaX 为例):

-- 设置支持图片的缓存,请谨慎使用,因为这种方式可能导致状态,还会造成内存泄露-- 详情:https://blog.csdn.net/wytwyt123456/article/details/106355429res.setSupportCacheGetterMap("getDrawable",true)
-- 获取 colorPrimary 颜色值-- R.attr.colorPrimarycolorPrimary=res.color.attr.colorPrimary-- 获取 android 的 colorPrimary 颜色值-- android.R.attr.colorPrimarycolorPrimaryAndroid=android.res.color.attr.colorPrimary-- 获取当前主题的 actionBarTheme 主题ID-- R.attr.actionBarThemeactionBarThemeId=res.id.attr.actionBarTheme-- 获取当前主题 actionBarTheme 中的 colorControlNormal 颜色值-- R.attr.actionBarTheme-- R.attr.colorControlNormalactionBarColorControlNormal=res(res.id.attr.actionBarTheme).color.attr.colorControlNormal-- 获取 seed 颜色-- R.color.seedseedColor=res.color.seed-- 获取 android 的 holo_blue_light 颜色-- android.R.color.holo_blue_lightholoBlueLightColor=android.res.color.holo_blue_light-- 使用 EMUI 的 R 类androidhwext={R=luajava.bindClass("androidhwext.R")}
androidhwext.res=res(androidhwext.R)
-- 或者androidhwext.res=res.getOrNewResWithRClass(androidhwext.R)

提示:此工具也支持在 Android 12 及以上获取系统壁纸色。详情请见 layout.aly

参与贡献

  1. Fork 本仓库
  2. 新建 Feat_xxx 分支
  3. 提交代码
  4. 新建 Pull Request

感谢

About

Easy access to resource data in AndroLua+

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages