MacGapProject / MacGap1

Desktop WebKit wrapper for HTML/CSS/JS applications.
Other
3.55k stars 209 forks source link

Any plans to enable userstyles? #94

Closed nheinric closed 10 years ago

nheinric commented 10 years ago

Subject says it all :)

I'm using a MacGap app from a 3rd-party service provider that loads up a site via document.location.replace, wiping out any local styles.

Just wondered if userstyles are in the pipeline, as that would be an easy way to handle the mods I need without bugging the upstream developers.

Thanks!

jeff-h commented 10 years ago

Can you make this a little more concrete? e.g. is the app you're talking about available on github?

I assume you are talking about something similar to Safari's preferences > Advanced > Style sheet which allows users to add their own CSS?

Fundamentally, MacGap makes a bunch of desktop/objective-C features available to Javascript. Can you propose a javascript call you wish MacGap provided in order to achieve what you want?

nheinric commented 10 years ago

Precisely: a mechanism for the end user to apply a local CSS stylesheet to whatever document is loaded in the webview (regardless of whether the underlying URL changes.)

(Unfortunately, the app is not available on github.)

It sounds like this would be more a function of the underlying WebKit code, rather than MacGap itself.

I'll have a poke around. Thanks!

jeff-h commented 10 years ago

If you have access to edit the actual objective-C code of the app you're talking about (and are brave enough to :), or want to write your own MacGap project to wrap around the site, you can certainly do what you're hoping to do; check out the userStyleSheet stuff at https://developer.apple.com/library/mac/documentation/Cocoa/Reference/WebKit/Classes/WebPreferences_Class/Reference/Reference.html#//apple_ref/occ/instm/WebPreferences/userStyleSheetEnabled

You'd need to setUserStyleSheetEnabled to YES and point setUserStyleSheetLocation at your CSS file location. Check out ContentView.m in the MacGap source for examples of other WebPreferences setup.

jeff-h commented 10 years ago

Incidentally, I also just came across some example code which injects a javascript file into a WebView which is showing an external site. See https://github.com/tamagokun/work-webmail/commit/a920d735d89d840a8d1b954aedb5d9ea57cc1c0a

You could add styles to the page via javascript added in this manner.

nheinric commented 10 years ago

Wow, thanks for taking the time to send these followups!