Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Safari > Preferences > Advanced > Style sheet injection #24

Open
gingerbeardman opened this issue May 23, 2023 · 1 comment
Open

Safari > Preferences > Advanced > Style sheet injection #24

gingerbeardman opened this issue May 23, 2023 · 1 comment

Comments

@gingerbeardman
Copy link

gingerbeardman commented May 23, 2023

This is not yet a concrete proposal but rather some notes and thinking out loud.

Background

I noticed that the user stylesheet chosen to Safari using Preferences > Advanced > Style sheet is applied without a flash of styled content.

So I wondered if I could use it to inject all PageExtender CSS?

Testing

I have chosen ~/safari.css as the file chosen in Safari preferences.

Different approaches

  1. @include all files within ~/.css folder
  • eg. @import ".css/letterboxd.com.css";
  • doesn't seem to work
    • I tried full paths, partial paths, files in same directory as ~/safari.css
    • maybe they disabled imports in this scenario?
    • or maybe i am doing something wrong?

  1. all CSS included inline
  • works
  • CSS is not specific to domain so everything applies to every site

  1. JS + all CSS inline scoped with domain
  • ~/.css/default.js
    • document.documentElement.setAttribute("data-location", window.location.href);
  • ~/safari.css
    • qualify CSS with domain of file
    • example
[data-location*="domain.com"] .selector {
  display: none;
}
  • would require a script to produce the correctly formatted qualified, inline css
  • WIP see below
@gingerbeardman
Copy link
Author

gingerbeardman commented May 23, 2023

This short PHP script will print out a concatenated CSS file, using CSS Nesting (support added in Safari 16.5) that can be used as ~/safari.css and Safari > Advanced > Style sheet

<?php
foreach (glob(".css/*.css") as $css) {
	print("\n\n/*\n\tFILE: ". basename($css) ."\n*/\n");
	
	$datalocation = '[data-location*="'.basename($css, '.css'). '"]';
	
	print("$datalocation {\n");
	print(file_get_contents($css));
	print("/* $datalocation */\n}\n");
}
?>
  • make sure to manually unwrap the entry for default.css
  • blank.css is not supported

I'm going to run with this setup for a while

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant