tomouchuu / mastodon-translate

Tampermonkey Script to add option to Translate Toots
The Unlicense
24 stars 2 forks source link

Reduce dependency on tampermonkey #12

Open tomouchuu opened 7 years ago

tomouchuu commented 7 years ago

So at the moment, you absolutely must have tampermonkey to use the script. It would be really awesome if we could reduce this dependency so it can be included in people's electron apps or even in people's own mastodon instances natively.

People who just use mastodon web and on a instance that doesn't have built in translations can then rely on tampermonkey to ensure their script is kept up to date.

I think first off, let's use fetch instead of that gm http script. Then need to look at what's the best way to release the script for electron/native developers.

tomouchuu commented 7 years ago

Just to add, the best way to almost certainly use npm for this. I guess best thing would be to abstract the current script from index.user.js into index.js and then have index.user.js reference index.js which means I just need to update the index.js for the script itself.

The only thing that would need changing in the tampermonkey script would be the version number

tomouchuu commented 7 years ago

So was playing around with this at the moment and unfortunately harder than I thought. The issue is because instances generally have a good Content Security Policy, this means that you can't call things not specified in this of which translate.uchuu.io is not so the script fails.

Refused to connect to 'https://translate.uchuu.io/en/text' because it violates the following Content Security Policy directive: "connect-src 'self' https://niu.moe/ wss://niu.moe/".

I'm assuming tampermonkey just bypasses this based on reading here https://github.com/scriptish/scriptish/wiki/GM_xmlhttpRequest so I could potentially look to making translate.uchuu.io use jsonp which should work but then I can't use fetch natively and means using something like: https://stackoverflow.com/questions/22780430/javascript-xmlhttprequest-using-jsonp#22780569

tomouchuu commented 7 years ago

The jsonp method is also a no go VM908:42 Refused to load the script 'https://translate.uchuu.io/en/text?callback=jsonp_callback_23953' because it violates the following Content Security Policy directive: "script-src 'unsafe-eval' 'self'".

I think the next step is likely going to be me setting up my own instance to get a native version sorted and then work with instance admins on implementing this in a way that's good to be potentially merged into mastodon itself.