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

[Suggestion] Image fetch location #3446

Open
yomukana opened this issue Feb 6, 2024 · 5 comments
Open

[Suggestion] Image fetch location #3446

yomukana opened this issue Feb 6, 2024 · 5 comments

Comments

@yomukana
Copy link

yomukana commented Feb 6, 2024

Cloudflare compresses images on 4cdn.org/%board/%filename, however changing this fetch address gives the uncompressed file. Not using 4chanX the following script works:

(function() {
"use strict"
for (const elem of document.querySelectorAll(`[href^="//i.4cdn.org"]`)) {
elem.href = elem.href + "?" + Math.floor(1);
}
})()

Is it possible to change the address 4chanX fetches from for the quick-download? I do not know if any version of the script I provided would work with the threadupdater.

Maybe unrelated but it could also be applied to s.4cdn.org. However I do not know the usage of this domain.

@ClawhammerLobotomy
Copy link

This appears to be fixable by modifying this piece of the userscript.
I don't know how to apply this to the actual project, and have just manually modified the userscript to test.
I don't know much about coffeescript, and the code in ImageCommon.coffee is not aligning with my installed userscript when I try to compile it, even before changes.

ImageCommon = {
//Other functions
    download: function(e) {
      var download, href, ref;
      if (this.protocol === 'blob:') {
        return true;
      }
      e.preventDefault();
      ref = this, href = ref.href+'?foo', download = ref.download;
      return CrossOrigin.file(href, function(blob) {
        var a;
        if (blob) {
          a = $.el('a', {
            href: URL.createObjectURL(blob),
            download: download,
            hidden: true
          });
          $.add(d.body, a);
          a.click();
          return $.rm(a);
        } else {
          return new Notice('warning', "Could not download " + href, 20);
        }
      });
    }
}

Specifically this line:
ref = this, href = ref.href, download = ref.download;
to:
ref = this, href = ref.href+'?foo', download = ref.download;

Adding ?ANYTHING after the image href when downloading will download the original size.

@yomukana
Copy link
Author

yomukana commented Mar 6, 2024

@ClawhammerLobotomy Wow thank you very much! Looking at the discussion in your pull request, I tried to make a 'random' version of your userscript-version provided here. However writing something like this:
testnegneg = '?' + Math.random().toString(36).slice(2)
ref = this, href = ref.href + testnegneg, download = ref.download;
breaks the download button's functionality. Do you have any solution to this?
Thanks for your great insight.

@ClawhammerLobotomy
Copy link

@yomukana
Did you check out my pull request?
It should already be updated with the randomized version, and it is working for me with the download button.

Your issue seems to be that you haven't declared testnegneg prior to using it, unless you didn't add it in your example.
The variables are defined at the start of the function for this. I added "search" here.

download: function(e) {
  var download, href, ref, search;
  if (this.protocol === 'blob:') {
    return true;
  }
  e.preventDefault();
  ref = this, href = ref.href, download = ref.download;
  search = Date.now() + Math.random().toString(20).substring(2);
  href = href + '?' + search;

@yomukana
Copy link
Author

yomukana commented Mar 11, 2024

@ClawhammerLobotomy Thanks! Yes I did read your pull request but it used the & operator which seemed unnecessary to me so I wanted to make my own version, but now everything is solved. Should I close the issue or wait until your new pull is merged?

@ClawhammerLobotomy
Copy link

It should probably remain open in case someone else searches for the issue.
Not sure how often pull requests are reviewed.
This info could at least serve as a workaround for someone who cares enough about the compression to implement themselves.

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

2 participants