├── .github └── ISSUE_TEMPLATE │ ├── bug.yml │ ├── config.yml │ └── suggestion.md ├── .gitignore ├── LICENSE ├── README.md ├── assets └── icons │ └── icon.png ├── firefox-manifest.json ├── manifest.json ├── package.json ├── src ├── amazon-ivs-worker.min.js ├── app.js ├── chrome │ └── app.js ├── firefox │ ├── app.js │ └── twitchnosub.js ├── patch_amazonworker.js └── twitchnosub.js ├── tools └── patch.js └── userscript └── twitchnosub.user.js /.github/ISSUE_TEMPLATE/bug.yml: -------------------------------------------------------------------------------- 1 | name: Bug Report 2 | description: File a bug report. 3 | title: "Bug: " 4 | labels: ["bug"] 5 | assignees: 6 | - besuper 7 | body: 8 | - type: dropdown 9 | id: version 10 | attributes: 11 | label: Version 12 | description: What version are you running? 13 | options: 14 | - Chromium 15 | - Firefox 16 | validations: 17 | required: true 18 | - type: input 19 | id: vod 20 | attributes: 21 | label: VOD link / channel link 22 | description: The URL where you encountered the error 23 | validations: 24 | required: false 25 | - type: textarea 26 | id: twitch-error 27 | attributes: 28 | label: Twitch error 29 | description: Fill this in if you encountered a Twitch player error. 30 | validations: 31 | required: false 32 | - type: textarea 33 | id: logs 34 | attributes: 35 | label: Console log output 36 | description: Please copy and paste logs related to TwitchNoSub and Twitch players from the developer console 37 | value: You can skip if the issue is not about VODs/lives 38 | render: shell 39 | validations: 40 | required: true 41 | - type: textarea 42 | id: additional-information 43 | attributes: 44 | label: Additional information 45 | description: Feel free to provide any additional information you have. 46 | placeholder: Additional information, screenshots, ... 47 | validations: 48 | required: false 49 | - type: checkboxes 50 | id: terms 51 | attributes: 52 | label: Verification 53 | description: By submitting this issue, you agree that you have correctly filled out this form. 54 | options: 55 | - label: I agree 56 | required: true 57 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | blank_issues_enabled: false -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/suggestion.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Suggestion 3 | about: Submit a suggestion 4 | title: '' 5 | labels: enhancement 6 | assignees: '' 7 | 8 | --- -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | package-lock.json -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2022 besuper 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # TwitchNoSub 2 | 3 | Be able to watch any sub-only vod on Twitch, integrated in the website and support every twitch features. 4 | 5 | Support chromium based browser (Chrome, Edge, Brave, Opera, ...) and Firefox. 6 | 7 | ## Download & installation 8 | 9 | ##### Chromium based browser 10 | Download the latest release in the [releases section](https://github.com/besuper/TwitchNoSub/releases) or clone the repo. 11 | 12 | You have to install the extension manually: 13 | 14 | - Go in manage extension (**chrome://extensions/** in chrome) 15 | - Make sure **Developer mode** is enabled 16 | - Hit **Load unpacked extension** and select the unzipped folder of the extension. 17 | 18 | If you use Chromium (not Chrome), you can pack the extension to get a .crx file you can drag & drop inside extensions page (which removes the need to have a dedicated directory for the extension on your hard drive) 19 | 20 | - Unzip the extension 21 | - In the parent directory of the extension, run the following command : `chromium --pack-extension=TwitchNoSub` 22 | - Drop the created crx file in the extensions page of your browser (make sure **Developer mode** is enabled, however it will not work) 23 | 24 | ##### Firefox 25 | Download the latest .**xpi** file in the [releases section](https://github.com/besuper/TwitchNoSub/releases). 26 | 27 | - Drag and drop the xpi file on Firefox 28 | - Click on "Add" in the little confirmation popup 29 | 30 | ## Warning 31 | 32 | This extension is still in work in progress, if there is any issue please report it. 33 | -------------------------------------------------------------------------------- /assets/icons/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/besuper/TwitchNoSub/c6a374e904508c0a3952e73ba7fce7427227f0b0/assets/icons/icon.png -------------------------------------------------------------------------------- /firefox-manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "TwitchNoSub", 3 | "version": "0.9.2", 4 | "description": "Show sub only VOD on Twitch", 5 | "manifest_version": 2, 6 | "icons": { 7 | "128": "assets/icons/icon.png" 8 | }, 9 | "web_accessible_resources": [ 10 | "src/firefox/app.js", 11 | "src/app.js", 12 | "src/patch_amazonworker.js" 13 | ], 14 | "content_scripts": [ 15 | { 16 | "matches": [ 17 | "https://*.twitch.tv/*" 18 | ], 19 | "js": [ 20 | "src/firefox/twitchnosub.js", 21 | "src/twitchnosub.js" 22 | ], 23 | "run_at": "document_start", 24 | "all_frames": true 25 | } 26 | ], 27 | "permissions": [ 28 | "https://*.twitch.tv/*", 29 | "https://static.twitchcdn.net/assets/*" 30 | ], 31 | "browser_specific_settings": { 32 | "gecko": { 33 | "id": "twitchnosub@besuper.com", 34 | "strict_min_version": "58.0" 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "TwitchNoSub", 3 | "version": "0.9.2", 4 | "description": "Show sub only VOD on Twitch", 5 | "manifest_version": 3, 6 | "icons": { 7 | "128": "assets/icons/icon.png" 8 | }, 9 | "web_accessible_resources": [ 10 | { 11 | "resources": [ 12 | "src/app.js", 13 | "src/chrome/app.js" 14 | ], 15 | "matches": [ 16 | "https://*.twitch.tv/*" 17 | ] 18 | } 19 | ], 20 | "content_scripts": [ 21 | { 22 | "matches": [ 23 | "*://*.twitch.tv/*" 24 | ], 25 | "js": [ 26 | "src/twitchnosub.js" 27 | ], 28 | "all_frames": true, 29 | "run_at": "document_start" 30 | } 31 | ], 32 | "host_permissions": [ 33 | "https://*.twitch.tv/*", 34 | "https://static.twitchcdn.net/assets/*" 35 | ], 36 | "permissions": [] 37 | } -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "twitchnosub", 3 | "version": "1.0.0", 4 | "description": "An extension to show sub only VOD on Twitch", 5 | "scripts": { 6 | "patch": "node tools/patch.js" 7 | }, 8 | "repository": { 9 | "type": "git", 10 | "url": "git+https://github.com/besuper/TwitchNoSub.git" 11 | }, 12 | "author": "besuper", 13 | "license": "ISC", 14 | "bugs": { 15 | "url": "https://github.com/besuper/TwitchNoSub/issues" 16 | }, 17 | "homepage": "https://github.com/besuper/TwitchNoSub#readme", 18 | "dependencies": { 19 | "amazon-ivs-player": "1.34.1" 20 | } 21 | } -------------------------------------------------------------------------------- /src/app.js: -------------------------------------------------------------------------------- 1 | // From vaft script (https://github.com/pixeltris/TwitchAdSolutions/blob/master/vaft/vaft.user.js#L299) 2 | function getWasmWorkerJs(twitchBlobUrl) { 3 | var req = new XMLHttpRequest(); 4 | req.open('GET', twitchBlobUrl, false); 5 | req.overrideMimeType("text/javascript"); 6 | req.send(); 7 | return req.responseText; 8 | } 9 | 10 | const oldWorker = window.Worker; 11 | 12 | window.Worker = class Worker extends oldWorker { 13 | constructor(twitchBlobUrl) { 14 | var workerString = getWasmWorkerJs(`${twitchBlobUrl.replaceAll("'", "%27")}`); 15 | 16 | const blobUrl = URL.createObjectURL(new Blob([` 17 | importScripts( 18 | '${patch_url}', 19 | ); 20 | ${workerString} 21 | `])); 22 | 23 | super(blobUrl); 24 | } 25 | } -------------------------------------------------------------------------------- /src/chrome/app.js: -------------------------------------------------------------------------------- 1 | const patch_url = "https://cdn.jsdelivr.net/gh/besuper/TwitchNoSub@master/src/patch_amazonworker.js"; -------------------------------------------------------------------------------- /src/firefox/app.js: -------------------------------------------------------------------------------- 1 | const patch_url = localStorage.getItem("tns_internal_patch_url"); -------------------------------------------------------------------------------- /src/firefox/twitchnosub.js: -------------------------------------------------------------------------------- 1 | localStorage.setItem("tns_internal_patch_url", chrome.runtime.getURL("src/patch_amazonworker.js")); -------------------------------------------------------------------------------- /src/patch_amazonworker.js: -------------------------------------------------------------------------------- 1 | async function fetchTwitchDataGQL(vodID) { 2 | const resp = await fetch("https://gql.twitch.tv/gql", { 3 | method: 'POST', 4 | body: JSON.stringify({ 5 | "query": "query { video(id: \"" + vodID + "\") { broadcastType, createdAt, seekPreviewsURL, owner { login } }}" 6 | }), 7 | headers: { 8 | 'Client-Id': 'kimne78kx3ncx6brgo4mv6wki5h1ko', 9 | 'Accept': 'application/json', 10 | 'Content-Type': 'application/json' 11 | } 12 | }); 13 | 14 | return resp.json(); 15 | } 16 | 17 | function createServingID() { 18 | const w = "0123456789abcdefghijklmnopqrstuvwxyz".split(""); 19 | let id = ""; 20 | 21 | for (let i = 0; i < 32; i++) { 22 | id += w[Math.floor(Math.random() * w.length)]; 23 | } 24 | 25 | return id; 26 | } 27 | 28 | async function isValidQuality(url) { 29 | const response = await fetch(url); 30 | 31 | if (response.ok) { 32 | const data = await response.text(); 33 | 34 | if (data.includes(".ts")) { 35 | // ts files should still use the h264 36 | return { codec: "avc1.4D001E" }; 37 | } 38 | 39 | if (data.includes(".mp4")) { 40 | // mp4 file use h265, but sometimes h264 41 | const mp4Request = await fetch(url.replace("index-dvr.m3u8", "init-0.mp4")); 42 | 43 | if (mp4Request.ok) { 44 | const content = await mp4Request.text(); 45 | 46 | return { codec: content.includes("hev1") ? "hev1.1.6.L93.B0" : "avc1.4D001E" }; 47 | } 48 | 49 | return { codec: "hev1.1.6.L93.B0" }; 50 | } 51 | } 52 | 53 | return null; 54 | } 55 | 56 | const oldFetch = self.fetch; 57 | 58 | self.fetch = async function (input, opt) { 59 | let url = input instanceof Request ? input.url : input.toString(); 60 | let response = await oldFetch(input, opt); 61 | 62 | // Patch playlist from unmuted to muted segments 63 | if (url.includes("cloudfront") && url.includes(".m3u8")) { 64 | const body = await response.text(); 65 | 66 | return new Response(body.replace(/-unmuted/g, "-muted"), { status: 200 }); 67 | } 68 | 69 | if (url.startsWith("https://usher.ttvnw.net/vod/")) { 70 | if (response.status != 200) { 71 | const vodId = url.split("https://usher.ttvnw.net/vod/")[1].split(".m3u8")[0]; 72 | const data = await fetchTwitchDataGQL(vodId); 73 | 74 | if (data == undefined) { 75 | return new Response("Unable to fetch twitch data API", { status: 403 }); 76 | } 77 | 78 | const vodData = data.data.video; 79 | const channelData = vodData.owner 80 | 81 | let resolutions = { 82 | "160p30": { 83 | "res": "284x160", 84 | "fps": 30 85 | }, 86 | "360p30": { 87 | "res": "640x360", 88 | "fps": 30 89 | }, 90 | "480p30": { 91 | "res": "854x480", 92 | "fps": 30 93 | }, 94 | "720p60": { 95 | "res": "1280x720", 96 | "fps": 60 97 | }, 98 | "1080p60": { 99 | "res": "1920x1080", 100 | "fps": 60 101 | }, 102 | "chunked": { 103 | "res": "1920x1080", 104 | "fps": 60 105 | } 106 | }; 107 | 108 | let sorted_dict = Object.keys(resolutions); 109 | sorted_dict = sorted_dict.reverse(); 110 | 111 | let ordered_resolutions = {}; 112 | 113 | for (const key in sorted_dict) { 114 | ordered_resolutions[sorted_dict[key]] = resolutions[sorted_dict[key]]; 115 | } 116 | 117 | resolutions = ordered_resolutions; 118 | 119 | const currentURL = new URL(vodData.seekPreviewsURL); 120 | 121 | const domain = currentURL.host; 122 | const paths = currentURL.pathname.split("/"); 123 | const vodSpecialID = paths[paths.findIndex(element => element.includes("storyboards")) - 1]; 124 | 125 | let fakePlaylist = `#EXTM3U 126 | #EXT-X-TWITCH-INFO:ORIGIN="s3",B="false",REGION="EU",USER-IP="127.0.0.1",SERVING-ID="${createServingID()}",CLUSTER="cloudfront_vod",USER-COUNTRY="BE",MANIFEST-CLUSTER="cloudfront_vod"`; 127 | 128 | const now = new Date("2023-02-10"); 129 | const created = new Date(vodData.createdAt); 130 | 131 | const time_difference = now.getTime() - created.getTime(); 132 | const days_difference = time_difference / (1000 * 3600 * 24); 133 | 134 | const broadcastType = vodData.broadcastType.toLowerCase(); 135 | 136 | let startQuality = 8534030; 137 | 138 | for (const [resKey, resValue] of Object.entries(resolutions)) { 139 | url = undefined; 140 | 141 | if (broadcastType === "highlight") { 142 | url = `https://${domain}/${vodSpecialID}/${resKey}/highlight-${vodId}.m3u8`; 143 | } else if (broadcastType === "upload" && days_difference > 7) { 144 | // Only old uploaded VOD works with this method now 145 | 146 | url = `https://${domain}/${channelData.login}/${vodId}/${vodSpecialID}/${resKey}/index-dvr.m3u8`; 147 | } else { 148 | url = `https://${domain}/${vodSpecialID}/${resKey}/index-dvr.m3u8`; 149 | } 150 | 151 | if (url == undefined) { 152 | continue; 153 | } 154 | 155 | const result = await isValidQuality(url); 156 | 157 | if (result) { 158 | const quality = resKey == "chunked" ? resValue.res.split("x")[1] + "p" : resKey; 159 | const enabled = resKey == "chunked" ? "YES" : "NO"; 160 | const fps = resValue.fps; 161 | 162 | fakePlaylist += ` 163 | #EXT-X-MEDIA:TYPE=VIDEO,GROUP-ID="${quality}",NAME="${quality}",AUTOSELECT=${enabled},DEFAULT=${enabled} 164 | #EXT-X-STREAM-INF:BANDWIDTH=${startQuality},CODECS="${result.codec},mp4a.40.2",RESOLUTION=${resValue.res},VIDEO="${quality}",FRAME-RATE=${fps} 165 | ${url}`; 166 | 167 | startQuality -= 100; 168 | } 169 | }; 170 | 171 | const header = new Headers(); 172 | header.append('Content-Type', 'application/vnd.apple.mpegurl'); 173 | 174 | return new Response(fakePlaylist, { status: 200, headers: header }); 175 | } 176 | } 177 | 178 | return response; 179 | } -------------------------------------------------------------------------------- /src/twitchnosub.js: -------------------------------------------------------------------------------- 1 | function injectScript(src) { 2 | const s = document.createElement('script'); 3 | s.src = chrome.runtime.getURL(src); 4 | s.onload = () => s.remove(); 5 | (document.head || document.documentElement).append(s); 6 | } 7 | 8 | const extensionType = window.chrome !== undefined ? "chrome" : "firefox"; 9 | 10 | console.log("[TNS] Found extension type : " + extensionType); 11 | 12 | injectScript(`src/${extensionType}/app.js`); 13 | injectScript("src/app.js"); -------------------------------------------------------------------------------- /tools/patch.js: -------------------------------------------------------------------------------- 1 | // Build patched amazon worker 2 | 3 | const fs = require("fs"); 4 | 5 | const amazon_worker = fs.readFileSync("node_modules/amazon-ivs-player/dist/assets/amazon-ivs-worker.min.js"); 6 | const patch = fs.readFileSync("src/patch_amazonworker.js"); 7 | 8 | fs.writeFileSync('src/amazon-ivs-worker.min.js', patch + amazon_worker); 9 | 10 | console.log("Worker patched!"); -------------------------------------------------------------------------------- /userscript/twitchnosub.user.js: -------------------------------------------------------------------------------- 1 | // ==UserScript== 2 | // @name TwitchNoSub 3 | // @namespace https://github.com/besuper/TwitchNoSub 4 | // @version 1.1.1 5 | // @description Watch sub only VODs on Twitch 6 | // @author besuper 7 | // @updateURL https://raw.githubusercontent.com/besuper/TwitchNoSub/master/userscript/twitchnosub.user.js 8 | // @downloadURL https://raw.githubusercontent.com/besuper/TwitchNoSub/master/userscript/twitchnosub.user.js 9 | // @icon https://raw.githubusercontent.com/besuper/TwitchNoSub/master/assets/icons/icon.png 10 | // @match *://*.twitch.tv/* 11 | // @run-at document-end 12 | // @inject-into page 13 | // @grant none 14 | 15 | // ==/UserScript== 16 | (function () { 17 | 'use strict'; 18 | 19 | // From vaft script (https://github.com/pixeltris/TwitchAdSolutions/blob/master/vaft/vaft.user.js#L299) 20 | function getWasmWorkerJs(twitchBlobUrl) { 21 | var req = new XMLHttpRequest(); 22 | req.open('GET', twitchBlobUrl, false); 23 | req.overrideMimeType("text/javascript"); 24 | req.send(); 25 | return req.responseText; 26 | } 27 | 28 | const oldWorker = window.Worker; 29 | 30 | window.Worker = class Worker extends oldWorker { 31 | constructor(twitchBlobUrl) { 32 | var workerString = getWasmWorkerJs(`${twitchBlobUrl.replaceAll("'", "%27")}`); 33 | 34 | const blobUrl = URL.createObjectURL(new Blob([` 35 | importScripts( 36 | 'https://cdn.jsdelivr.net/gh/besuper/TwitchNoSub@master/src/patch_amazonworker.js', 37 | ); 38 | ${workerString} 39 | `])); 40 | super(blobUrl); 41 | } 42 | } 43 | })(); --------------------------------------------------------------------------------