Skip to content

Instantly share code, notes, and snippets.

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 687766616e/d4fd155d1c4f0532911ed262a6f37a50 to your computer and use it in GitHub Desktop.
Save 687766616e/d4fd155d1c4f0532911ed262a6f37a50 to your computer and use it in GitHub Desktop.
// ==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={&quot;key&quot;:&quot;#@150e0cbab4588892a54&quot;,&quot;logo&quot;:&quot;&quot;,&quot;playlist&quot;:[{&quot;url&quot;:&quot;' + videoLink + '&quot;}],&quot;plugins&quot;:{&quot;controls&quot;:{&quot;url&quot;:&quot;http://hk.adx.nextmedia.com/uvp/swf/flowplayer.controls-3.2.14.swf&quot;,&quot;playlist&quot;:false,&quot;stop&quot;:false,&quot;autoHide&quot;:true,&quot;background&quot;:&quot;#000000&quot;},&quot;dock&quot;:{&quot;right&quot;:15,&quot;horizontal&quot;:false,&quot;width&quot;:&quot;10pct&quot;,&quot;autoHide&quot;:true},&quot;dfp&quot;:{&quot;url&quot;:&quot;http://hk.adx.nextmedia.com/uvp2/swf/flowplayer.dfp-nextmedia.com-1.7-3-dev.swf&quot;,&quot;linearAdLabel&quot;:{&quot;advertisementLabel&quot;:&quot;advertisementLabel&quot;,&quot;type&quot;:&quot;top&quot;,&quot;content&quot;:&quot;Advertisement : Your video will resume in {time-left} seconds.&quot;},&quot;skipAdButton&quot;:{&quot;show&quot;:true,&quot;content&quot;:&quot;skip ad rrtrttrrt&quot;,&quot;type&quot;:&quot;right&quot;,&quot;fontSize&quot;:12,&quot;fontColor&quot;:&quot;#ffffff&quot;,&quot;fontFamily&quot;:&quot;Arial&quot;},&quot;debug&quot;:false},&quot;advertisementLabel&quot;:{&quot;url&quot;:&quot;http://hk.adx.nextmedia.com/uvp2/swf/flowplayer.content-3.2.8.swf&quot;,&quot;top&quot;:0,&quot;width&quot;:400,&quot;height&quot;:24,&quot;border&quot;:&quot;none&quot;,&quot;style&quot;:{&quot;body&quot;:{&quot;fontSize&quot;:12,&quot;fontFamily&quot;:&quot;Arial&quot;,&quot;textAlign&quot;:&quot;center&quot;,&quot;color&quot;:&quot;#ffffff&quot;}},&quot;backgroundColor&quot;:&quot;rgba(20, 20, 20, 0.5)&quot;,&quot;display&quot;:&quot;none&quot;}},&quot;playerId&quot;:&quot;flow_player&quot;,&quot;clip&quot;:{&quot;autoPlay&quot;: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