简体   繁体   English

如何控制动态类名称,这些动态类名称是使用用户定义的过滤器或其他方法通过CSS模块或样式化组件自动生成的

[英]How to control dynamic class names which are auto-generated via CSS modules or styled-components with user-defined filters or other methods

Many websites today auto-generate dynamic class names via CSS modules or styled-components. 如今,许多网站都通过CSS模块或样式化组件自动生成动态类名。 This practice has the unfortunate and perhaps even deliberately malicious effect of disabling many user-defined filters and/or scripts; 这种做法具有禁用许多用户定义的过滤器和/或脚本的不幸甚至是故意的恶意效果; eg Reddit overrides all manner of client-side cosmetic changes; 例如,Reddit会覆盖所有形式的客户端外观更改; even simple things like karma are being forced upon the user due to the fact that there's apparently no persistent global identifier which the user could invoke to forbid the display of karma: 由于似乎没有持久的全局标识符可供用户调用以禁止显示业力,因此甚至将诸如业力之类的简单事情也强加给用户:

An example screenshot of Reddit code illustrating the dynamic class names at hand Reddit代码的示例屏幕快照,展示了手头的动态类名

I think this is authoritarian, inappropriate, and creates a horrible user experience. 我认为这是专制的,不适当的,并且会带来可怕的用户体验。 I don't believe it's reasonable that websites should exercise this kind of control. 我认为网站应该进行这种控制是不合理的。 What exactly can the user do to reign in these seemingly un-manipulable dynamic class names? 用户究竟能做什么来统治这些看似无法操纵的动态类名? eg, is there a way to reverse engineer the build processes used by CSS modules or styled-components in order to then inject the proper identifiers into a user-defined filter and/or script? 例如,是否有一种方法可以对CSS模块或样式化组件使用的构建过程进行反向工程,以便随后将适当的标识符注入用户定义的过滤器和/或脚本中? Or are there better methods? 还是有更好的方法?

Note: I've already asked and received no decent response to this question on Webmaster, UX, and SuperUser. 注意:在Webmaster,UX和SuperUser上,我已经问过这个问题,但没有得到很好的答复。 Is this the end of the road? 这是路的尽头吗? Or is there a StackOverflow guru with a workable solution? 还是有一个带有可行解决方案的StackOverflow专家?

To hide karma spans on a comments page on Reddit, today, you could run the following JavaScript: 今天,要在Reddit的评论页面上隐藏业力跨度,您可以运行以下JavaScript:

Array.from(document.querySelectorAll('span')).filter(i => /(\d+)\spoint/.test(i.innerHTML)).forEach(i => i.style.display = 'none');

Tested it here . 在这里测试
However, it only hides karma on the rendered comments, not on the ones that are not yet loaded. 但是,它仅在已渲染的注释上隐藏业力,而不在尚未加载的注释上业力。

To programatically open all "moreComments" links on a page, you'd need to run: 要以编程方式打开页面上的所有“ moreComments”链接,您需要运行:

Array.from(document.querySelectorAll('div')).filter(i => /moreComments-/.test(i.id)).forEach(i => i.querySelector('p').click())

Depending on how many hidden comments are on the page, you'd need to wait a while until all requests resolve and all comments are rendered. 根据页面上隐藏的评论数,您需要等待一会儿,直到所有请求都解决并呈现所有评论。

At which point running the first line will hide all karma spans on the page. 在这一点上,运行第一行将隐藏页面上的所有业障跨度。


And this might not work tomorrow, as Reddit own that code and have the right, the ability and the resources to change its inner structure, layout or design as they see fit, any number of times a day, so that any puny attempts of altering the rendered output of their service, by coder wannabes like me and you, remain futile. 明天这可能行不通,因为Reddit拥有该代码,并且拥有权利,能力和资源来改变其内部结构,布局或设计,以他们认为合适的方式每天进行任意次数的更改,以便进行任何微小的更改尝试通过像我和您这样的编码人员想要提供的服务的输出仍然是徒劳的。


Edit: Ever since I answered your question I wanted to provide some helpful insight on how to approach StackOverflow. 编辑:自从我回答了您的问题以来,我想就如何处理StackOverflow提供一些有用的见解。 I hope you find it helpful or, at least, entertaining. 我希望您发现它对您有所帮助,或者至少是娱乐性的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM