![]() If we pass all of those error checks, now we move on to the actual meat of the code: Retrieving the id of the latest character uploaded to the Mugen Archive, and one last check to make sure the character is actually playable! The code will rerun once the page renders properly. In both of those pages, just wait by returning. This code makes sure the page centers on the content of the page and not on the header section, which serves the dual purpose of making it easier to download the Mugen character, while also ensuring the character is downloadable if there's no content section, there's nothing to download, which means that the page either: 1) rendered improperly, or 2) is in a weird CloudFlare "verify" state, where it tries to make sure you're not a bot trying to access the page. Once that's done, we return from the function and do not execute any more code.Īssuming it's not an error page, we move on to the next section, which covers another error I ran into: If it's there, we send a message to the background script to blacklist this page it's gone and we no longer want it to show up in our searches from now on. So we check for the standard error message ont he page. Now that we have the id stored, we move on to the next part, checking for more errors!ĭuring my testing, I found that occassionally someone had deleted a character entry, and that page just throws an error page instead of the rest of the information I wanted. ![]() If there is an id, we remove any extra info Mugen Archive attached to the id (such as the downloadable character's name and such) by splitting on any dashes and returning the first element returned from that If there's no id, we return immediately as it's not a valid page, or an error happened (there's multiple error checks throughout this) URLSearchParams basically parses the URL string you give it, and makes it so we can retrieve sections of it without having to parse strings and all that. is the part of the URL after the question mark Honestly it could be multiple functions, and probably should be for testing purposes, but this was something fast and quick for a friend so I didn't adhere to all the best standards, haha.įirst off, we want to get the id from the URL (that number at the end of the above URL), and this bit of code handles that easily: The init function is more complex, so I've broken it into parts. The type tells the background script what to do with the data. We can pass any sort of data we want, an Object, String, whatever. The sendMessage function is very easy using Chrome runtime APIs: Init does the lion's share of the work, validating that it's an appropriate character page we've landed on, and sendMessage sends data to the background script for storage (of course). The content script consists of exactly two functions: sendMessage and init. If it is, great! If not, we store the number as an invalid page. Once it does, it checks to see if it's a valid character page or not based on a number of criteria. So the plugin basically randomizes that last number at the end there, and navigates to the new URL. Those URLs all look something like this: Last time we mentioned that we only want to run this code on download.php pages, which is the base url that all Mugen Archive file download pages have. the script that gets run when we navigate to certain pages of the site. Today I'll be focusing on the content script, i.e. ![]() If you recall from the last entry ( ), we're making a web extension, specifically for Chrome/Opera, that will randomly pick a character entry from the Mugen Archive website. A long time coming, but since I'm laid up in bed sick and can't get up to much, I figured I'd continue this series as well.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |