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

Question: how do I subscribe to [these rules](https://github.com/tumpio/requestcontrol/tree/master/rules)?? #152

Open
rgiotxy opened this issue Jul 10, 2021 · 7 comments
Labels

Comments

@rgiotxy
Copy link

rgiotxy commented Jul 10, 2021

Hi! Sorry! I'm new here and I have no idea what I'm doing. I know this is a dumb question, but how do I subscribe to these rules? There is no "subscribe" button, and on the extension there's only an "import from file" button (not from the internet), yet, on the folder, there's no "download" button to download all files to storage at once so I can then import them into the extension afterwards, and trying to manually open each file shows no individual "download" button that I can see either. How do I subscribe to these rules and/or import these rules to my extension?

@rusty-snake
Copy link
Contributor

rusty-snake commented Jul 11, 2021

IDK from where you got the impression that there is a subscribe function in RC, but AFAIK there is no such feature. Actually a subscribe function is a bad idea IMHO because it of the power of RC-rules. Unlike uB for example where a bad list could either block everything or allow everything, a bad RC rule can redirect you to a faked login page for example.

on the folder, there's no "download" button to download all files to storage at once so I can then import them into the extension afterwards

You can down load the repository:

Screenshot_2021-07-11_09-14-55-fs8

and trying to manually open each file shows no individual "download" button that I can see either.

Click on the "Raw" button, then you can Ctrl+S the file.

import these rules to my extension?

Open a new tab, open the console (https://developer.mozilla.org/en-US/docs/Tools/Web_Console#opening_the_web_console), allow pasting (and understand why it is not allowed by default) and paste the following (UNTESTED edit seems to work):

fetch("https://api.github.com/repos/tumpio/requestcontrol/contents/rules")
.then(function (response) {return response.json()})
.then(function (data) {return data.map(function (elem) {return elem.name})})
.then(function (rules) {return rules.map(function (rule) {return fetch("https://raw.githubusercontent.com/tumpio/requestcontrol/master/rules/" + rule).then(function (data) {return data.json()})})})
.then(function (rules) {return Promise.all(rules).then(function (rules) {console.log(JSON.stringify(rules.flat()))})})

Then you can copy the result and save it to a file.


edit:

Improved version:

fetch("https://api.github.com/repos/tumpio/requestcontrol/contents/rules").then(resp => resp.json())
.then(files => files.map(file => file.name))
.then(filenames => filenames.map(filename => fetch("https://raw.githubusercontent.com/tumpio/requestcontrol/master/rules/" + filename).then(resp => resp.json())))
.then(rules => Promise.all(rules).then(rules => document.getElementsByTagName("html")[0].innerText = JSON.stringify(rules.flat())))

And improved a second time:

fetch("https://api.github.com/repos/tumpio/requestcontrol/contents/rules")
    .then(resp => resp.json())
    .then(files => files.map(file => file.name))
    .then(filenames => {
        return filenames.map(filename => {
            return fetch(
                "https://raw.githubusercontent.com/tumpio/requestcontrol/master/rules/" + filename
            ).then(resp => resp.json())
        })
    })
    .then(rules => Promise.all(rules).then(rules => {
        document.getElementsByTagName("html")[0].innerHTML = `
            <body>
              <h1>
                All RequestControl Rules
              </h1>
              <p>
                Copy the text below, put it in a json file (e.g. RequestControl-Rules.json) and
                import it in RequestControl.
              </p>
              <code></code>
            </body>
        `;
	document.getElementsByTagName("code")[0].innerText = JSON.stringify(rules.flat());
    }));

@tumpio
Copy link
Owner

tumpio commented Jul 12, 2021

There is no subscribe feature. You can only import rules from a local file. Github also allows to download a single file using the "Raw" link button.

Support for manually importing rules listed in the rules folder or from a custom source could be added.

@rgiotxy
Copy link
Author

rgiotxy commented Jul 13, 2021

Let me see if I understand this correctly (I'm really new to this and may have misunderstood): @rusty-snake's solution requires me to use a keyboard shortcut Ctrl-Shift-K and @tumpio's requires me to use a keyboard shortcut Ctrl-S? Is that correct, or did I misunderstand what you said? Because, if it is so, clearly I should have mentioned earlier (my bad, I was planning to say it but wound up forgetting to) that I'm using this extension on Android and, whereas my keyboard actually does have a Ctrl and a Shift keys (never tried to use them together, though), I have yet to figure out how to summon the keyboard when I'm not typing…

…I suppose I could try to create a new file and simply paste the content of the rules there? If so, what format should the file be on and what app should I use to create it? Maybe a .txt file from Google Drive would suffice? To be honest, I don't see why there doesn't seem to be a mobile-friendly download button on GitHub… Then I could just download the files and import them directly… (Maybe there's a userscript I could install that adds a clickable download button?)

@rgiotxy rgiotxy closed this as completed Jul 13, 2021
@rgiotxy rgiotxy reopened this Jul 13, 2021
@rusty-snake
Copy link
Contributor

My solution does not work in Firefox for Android, however you can do it iin a Desktop Firefox, Chrome, Edge, Vivaldi, Safari, Opera, Epiphany, ... and then copy the result to your phone (e.g. via g-drive).

Instead of Ctrl+S you can use Save (page) as or Save link target as or whatever this is called. (Maybe long press on the raw button?)

I suppose I could try to create a new file and simply paste the content of the rules there?

All rules in one file requires you to slightly edit the rules. (That what my code does)

what format should the file be

It's a JSON file

what app I should use to create it

You can use every app that can create plain text files (.txt).

@rgiotxy
Copy link
Author

rgiotxy commented Jul 15, 2021

My solution does not work in Firefox for Android, however you can do it iin a Desktop Firefox, Chrome, Edge, Vivaldi, Safari, Opera, Epiphany, ... and then copy the result to your phone (e.g. via g-drive).

I'll try that when I have a computer available, which might not be any time soon.

Instead of Ctrl+S you can use Save (page) as or Save link target as or whatever this is called. (Maybe long press on the raw button?)

That didn't work, I don't see any "save" option other than "save as PDF" when inside the "raw" file, and long pressing the "raw" button doesn't provide any options other than "open link in new tab", "open link in private tab", etc.

All rules in one file requires you to slightly edit the rules. (That what my code does)

Do you mind explaining your answer to me again, then, please? Try to imagine you're talking to a child kkkkkkkkk I understand that when I get a computer I need to go to the "raw" file (?), press Ctrl-Shift-K and… paste your code into the web console? Which, just to point out in case it's relevant, I'd only ever heard of once prior to your mentioning it and have never actually used before, so I have no idea what to expect when I get there. Is that it? @tumpio's solution, if I understand it correctly, doesn't require doing that, yes? Yet your solution involves Ctrl-S, same as his? So, and please don't take this as me being anything other than genuinely confused, why do I need your code? What does it do? What would happen if I tried to save the files, send them to my mobile and import them without inserting your code on this web console?

what format should the file be

It's a JSON file

what app I should use to create it

You can use every app that can create plain text files (.txt).

Er… I don't have any app in mind, I was thinking maybe if I opened a context menu on the background of GDrive and pressed "new" maybe there would be a .txt option? Could I change the extension then? Later? After downloading from GDrive to the phone? If I do your solution, the result will still be a JSON file, right? So I don't really need to know how to create one in my mobile? And, if I did find out how, you say I couldn't simply copy and paste the rules into a blank JSON file anyway, right?

@rusty-snake
Copy link
Contributor

The difference between the solutions is that @tumpio solution give you 14 files that you need to import while my script merges them into one "file".

About the usage of my script, you don't need to run it on a raw page. It doesn't matter where you run it as long as there is no SOP/CORS/CSP/WHATEVER that disallows the fetch of one of the resource. And the two later versions override the content of the page.

@rgiotxy
Copy link
Author

rgiotxy commented Jul 17, 2021

Oooh! Very cool! Thank you! Both for the code and for the clarification!

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

No branches or pull requests

3 participants