IsThereAnyDeal / AugmentedSteam

Augments your Steam Experience
https://augmentedsteam.com
GNU General Public License v3.0
1.37k stars 84 forks source link

Feature suggestion redirect to community hub if store page removed #294

Open kriki200 opened 5 years ago

kriki200 commented 5 years ago

IT would be nice to get auto redirected to the comunity hub, if the store page has been removed, for example: Alice: Madness Returns.

MxtOUT commented 5 years ago

Could you give me the link for the store page of Alice: Madness Returns?

kriki200 commented 5 years ago

As far as I know there isb't any since its been removed. Here's a hub link: https://steamcommunity.com/app/19680/.

MxtOUT commented 5 years ago

Ok, I just needed the appid, thanks

Revadike commented 5 years ago

Good suggestion! Currently, there actually exists 2 options for this (one by me):

Both use entire diffent approaches to solving this problem. Both solutions have their up- and downsides, but overall I think @rafael-gssa's solution is more efficient, as it reduces the requests that are needed. Mind that my userscript checks for region locked store pages too.

Revadike commented 5 years ago

I actually found another excellent userscript by @Ryzhehvost. He seems to be using roughly the same solution as @rafael-gssa, but he tries to cover up the added hashes by replacing history, among other things.

rafaelgomesxyz commented 5 years ago

There's actually another alternative that I think is much better, using the webRequest API.

We can listen to a onHeadersReceived event coming from URLs that match either *://*.store.steampowered.com/app/* or *://*.store.steampowered.com/sub/*, and then check if the status code is 302. In that case, we then redirect the request.

Here's a sample extension that does this:

manifest.json

{
  "manifest_version": 2,
  "name": "Steam Redirector",
  "version": "1.0.0",
  "background": {
    "scripts": ["background.js"]
  },
  "permissions": [
    "*://*.store.steampowered.com/app/*",
    "*://*.store.steampowered.com/sub/*",
    "webRequest",
    "webRequestBlocking"
  ]
}

background.js

function onHeadersReceived(details) {
  const response = {};

  if (details.statusCode === 302) {
    const matches = details.url.match(/(app|sub)\/(\d+)/);

    if (matches) {
      const type = matches[1];
      const id = matches[2];

      response.redirectUrl = `https://steamcommunity.com/${type}/${id}`;
    }
  }

  return response;
}

const filter = {
  urls: ['*://*.store.steampowered.com/app/*', '*://*.store.steampowered.com/sub/*'],
  types: ['main_frame']
};

const extraInfoSpec = ['blocking'];

chrome.webRequest.onHeadersReceived.addListener(onHeadersReceived, filter, extraInfoSpec);

You can see it in action by extracting this .zip file and loading it as an unpacked extension on Chrome:

steam-redirector.zip

The webRequest and webRequestBlocking permissions could be optional (https://developer.chrome.com/apps/permissions) so that the user grants them only if they want to use this feature.

If this method is acceptable, I can try making a PR.

Revadike commented 4 years ago

@rafaelgssa are you planning to make a PR?

rafaelgomesxyz commented 4 years ago

Sure, I'll see if I can work on it this week.

Revadike commented 4 years ago

Also, like my userscript, pages with error "this is not available in your region" I think should also be redirected.

rafaelgomesxyz commented 4 years ago

Made a PR. But I think redirecting games that are not available in the region belong in a separate issue, because that has to be handled in the content script side, it's not possible to detect that through webRequest. I can try making a PR for that as well, though.

Rudokhvist commented 4 years ago

I even have doubts if not available in region apps should be redirected at all. Maybe it's better to just add link to steamdb to that page, so that user could understand, why app is not available, and go to steamdb/community hub if needed.

Revadike commented 4 years ago

Made a PR. But I think redirecting games that are not available in the region belong in a separate issue, because that has to be handled in the content script side, it's not possible to detect that through webRequest. I can try making a PR for that as well, though.

Sure, it uses a different method, but it still belongs to the redirect feature, as it needs the same user options.

Revadike commented 3 years ago

Hmm, I wish I had this feature today. I guess I have to resort to an userscript for now.