Forked from davitai/apple_daily_section_expander.user.js
Created
April 19, 2019 02:34
-
-
Save 687766616e/d4fd155d1c4f0532911ed262a6f37a50 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Apple Daily Section Expander | |
// @namespace AppleDailySectionExpander | |
// @description Expand all articles in one section, no need to click one by one | |
// @include https://hk.news.appledaily.com/daily/local/* | |
// @include https://hk.news.appledaily.com/daily/international/* | |
// @include https://hk.finance.appledaily.com/daily/finance/* | |
// @include https://hk.entertainment.appledaily.com/daily/entertainment/* | |
// @include https://hk.sports.appledaily.com/daily/sports/* | |
// @include https://hk.lifestyle.appledaily.com/* | |
// @require https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js | |
// @grant GM_xmlhttpRequest | |
// ==/UserScript== | |
var urls = []; | |
if (location.href.indexOf("https://hk.lifestyle.appledaily.com/") === 0) { | |
GM_xmlhttpRequest({ | |
method: "GET", | |
url: location.href.replace("https://hk.lifestyle.appledaily.com/", "https://hk.appledaily.com/archive/index/"), | |
onerror: function() { | |
alert("Error"); | |
}, | |
onload: function(rs) { | |
var ArchiveContainer = $(rs.responseText).find("div#tab2"); | |
$(ArchiveContainer).find("a").each(function () { | |
var url = $(this).attr("href"); | |
if (url != null && url.indexOf("https://")===0 && url!=urls[urls.length-1]) { | |
urls.push(url); | |
} | |
}); | |
getNewsContents(); | |
} | |
}); | |
} else { | |
GM_xmlhttpRequest({ | |
method: "GET", | |
url: location.href.replace(/\D+/, "https://hk.appledaily.com/archive/index/"), | |
onerror: function() { | |
alert("Error"); | |
}, | |
onload: function(rs) { | |
var category = location.href.replace("/daily", "").replace(/\d{8}\//, ""); | |
var ArchiveContainer = $(rs.responseText).find("div#tab1"); | |
$(ArchiveContainer).find("a").each(function () { | |
var url = $(this).attr("href"); | |
if (url != null && url.indexOf(category)===0 && url!=urls[urls.length-1]) { | |
urls.push(url); | |
} | |
}); | |
getNewsContents(); | |
} | |
}); | |
} | |
function getNewsContents() { | |
if (urls.length > 0) { | |
$("div.content").css("display", "none"); | |
for (i=0; i<urls.length; ++i) { | |
var newsNode = $("<div></div>").insertBefore("div.content"); | |
getNewsContent(urls[i], newsNode); | |
} | |
} | |
} | |
function getNewsContent(url, newsNode) { | |
GM_xmlhttpRequest({ | |
method: "GET", | |
url: url, | |
onerror: function() | |
{ | |
alert("Error"); | |
}, | |
onload: function(rs) { | |
var articleContent = $(rs.responseText).find("div#articleContent"); | |
$(articleContent).find('a[rel="fancybox-button"]').attr("target", "_blank"); | |
$(articleContent).find('div#video_player').css("width", "1040px"); | |
var videoImageLink = rs.responseText.match(/Player\.setInitialImage\('([^']+)'\);/); | |
if (videoImageLink != null) { | |
var videoLink = rs.responseText.match(/http:\/\/video.appledaily.com.hk\/[^\.]+.mp4/); | |
$(articleContent).find("div#video_player").append('<img src="' + videoImageLink[1] + '" height="293" width="520" style="float:right" /><div class="flow_player" id="flow_player" style="background-color: rgb(0, 0, 0); color: rgb(255, 255, 255); width: 520px; height: 293px;"><object id="flow_player_api" name="flow_player_api" data="http://hk.adx.nextmedia.com/uvp/swf/flowplayer.commercial-3.2.14.swf" type="application/x-shockwave-flash" height="100%" width="100%"><param name="allowfullscreen" value="true"><param name="allowscriptaccess" value="always"><param name="wmode" value="transparent"><param name="quality" value="high"><param name="bgcolor" value="#000000"><param name="flashvars" value="config={"key":"#@150e0cbab4588892a54","logo":"","playlist":[{"url":"' + videoLink + '"}],"plugins":{"controls":{"url":"http://hk.adx.nextmedia.com/uvp/swf/flowplayer.controls-3.2.14.swf","playlist":false,"stop":false,"autoHide":true,"background":"#000000"},"dock":{"right":15,"horizontal":false,"width":"10pct","autoHide":true},"dfp":{"url":"http://hk.adx.nextmedia.com/uvp2/swf/flowplayer.dfp-nextmedia.com-1.7-3-dev.swf","linearAdLabel":{"advertisementLabel":"advertisementLabel","type":"top","content":"Advertisement : Your video will resume in {time-left} seconds."},"skipAdButton":{"show":true,"content":"skip ad rrtrttrrt","type":"right","fontSize":12,"fontColor":"#ffffff","fontFamily":"Arial"},"debug":false},"advertisementLabel":{"url":"http://hk.adx.nextmedia.com/uvp2/swf/flowplayer.content-3.2.8.swf","top":0,"width":400,"height":24,"border":"none","style":{"body":{"fontSize":12,"fontFamily":"Arial","textAlign":"center","color":"#ffffff"}},"backgroundColor":"rgba(20, 20, 20, 0.5)","display":"none"}},"playerId":"flow_player","clip":{"autoPlay":false}}"></object></div>'); | |
} | |
$(newsNode).html('<hr /><br /><a href="' + url + '" target="_blank">' + url + '</a>' + $(articleContent).html()); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment