Skip to content

Instantly share code, notes, and snippets.

@dodikk
Created July 31, 2018 12:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dodikk/e028c03cd809271c950c135a3abd4240 to your computer and use it in GitHub Desktop.
Save dodikk/e028c03cd809271c950c135a3abd4240 to your computer and use it in GitHub Desktop.
Javascript injection in WKWebView
var videoTags = document.getElementsByTagName('video');
var result = [];
result.push('====\n')
for (var i = 0; i < videoTags.length; i++)
{
// result.push("====singleVideoTag \n");
var singleVideoTag = videoTags[i];
var sourceChildTags = singleVideoTag.getElementsByTagName('source');
for (var j = 0; j < sourceChildTags.length; j++)
{
// result.push("==singleSourceTag \n");
var singleSourceTag = sourceChildTags[j];
var videoSourceUrl =
singleSourceTag.getAttribute('src')
.toString()
.trim()
.toLowerCase();
result.push(videoSourceUrl);
var isHttp = videoSourceUrl.startsWith('http://');
if (isHttp)
{
var httpsSourceUrl = videoSourceUrl.replace('http://', 'https://');
result.push(httpsSourceUrl);
singleSourceTag.setAttribute('src', httpsSourceUrl);
}
else
{
result.push('http scheme not found');
}
}
}
result.push('====\n')
result.toString();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment