Skip to content

Instantly share code, notes, and snippets.

@stephenway
Created September 13, 2015 04:52
Show Gist options
  • Save stephenway/89c35c20f2f08a214fe9 to your computer and use it in GitHub Desktop.
Save stephenway/89c35c20f2f08a214fe9 to your computer and use it in GitHub Desktop.
Amazon S3 Directory Listing for Web Fonts
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>*</AllowedOrigin>
<AllowedMethod>GET</AllowedMethod>
<AllowedHeader>*</AllowedHeader>
</CORSRule>
</CORSConfiguration>
<html>
<head>
<!--
Amazon S3 Bucket listing.
Copyright (C) 2008 Francesco Pasqualini
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<title>webfonts</title>
<style>
html {
}
body {
background-color: #ffde00;
font-size: 18px;
margin:0;
padding:0;
}
header {
background-color: black;
padding: 1em;
height: 100px;
}
header h1 {
color: white;
font-family: "Andale Mono";
-moz-user-select: none;
-webkit-user-select: none;
user-select: none;
}
header code {
color: #b98bae;
}
header code::selection, header code .string::selection {
background-color: #999 !important;
}
header code .string {
color: #a0b56f !important;
}
header div {
float: left;
position: relative;
}
.header-left {
width: 25%;
}
.header-right {
width: 75%;
margin-top: 40px;
}
pre {
-webkit-font-smoothing: none;
font-family: "Andale Mono";
margin-left: -250px;
}
a, a:hover, a:focus, a:active {
color: red;
}
::selection {
background-color: rgba(255,255,255,1);
}
.question {
color: #444;
font-size: 32px;
border: 1px solid black;
border-radius: 50%;
width: 37px;
height: 37px;
display: inline-block;
text-decoration: none;
}
.question:hover {
color: #ffde00;
background-color: #444;
}
</style>
<SCRIPT>
//document.write(window.location.search);
function getSpace(s,l){
var ret = "";
while(s.length+ret.length<l){
ret = ret + " ";
}
return ret;
}
location.querystring = (function() {
// The return is a collection of key/value pairs
var result = {};
// Gets the query string with a preceeding '?'
var querystring = location.search;
// document.location.search is empty if a query string is absent
if (!querystring)
return result;
// substring(1) to remove the '?'
var pairs = querystring.substring(1).split("&");
var splitPair;
// Load the key/values of the return collection
for (var i = 0; i < pairs.length; i++) {
splitPair = pairs[i].split("=");
result[splitPair[0]] = splitPair[1];
}
return result;
})();
function createRequestObject(){
var request_o; //declare the variable to hold the object.
var browser = navigator.appName; //find the browser name
if(browser == "Microsoft Internet Explorer"){
/* Create the object using MSIE's method */
request_o = new ActiveXObject("Microsoft.XMLHTTP");
}else{
/* Create the object using other browser's method */
request_o = new XMLHttpRequest();
}
return request_o; //return the object
}
/* You can get more specific with version information by using
parseInt(navigator.appVersion)
Which will extract an integer value containing the version
of the browser being used.
*/
/* The variable http will hold our new XMLHttpRequest object. */
var http = createRequestObject();
function getList(){
http.open('get', location.protocol+'//'+location.hostname);
http.onreadystatechange = handleList;
http.send(null);
}
function handleList(){
/* Make sure that the transaction has finished. The XMLHttpRequest object
has a property called readyState with several states:
0: Uninitialized
1: Loading
2: Loaded
3: Interactive
4: Finished */
if(http.readyState == 4){ //Finished loading the response
/* We have got the response from the server-side script,
let's see just what it was. using the responseText property of
the XMLHttpRequest object. */
var response = http.responseXML;
filex = response.getElementsByTagName('Contents');
res = '';
fileList = new Array();
for(i=0; i<filex.length; i++){
fileData =new Array();
fileList[i] = fileData;
size = filex[i].getElementsByTagName('Size')[0].firstChild.data;
name = filex[i].getElementsByTagName('Key')[0].firstChild.data;
lastmod = filex[i].getElementsByTagName('LastModified')[0].firstChild.data;
link = "<A HREF=\""+name+"\">"+name+"</A>";
fileData[0] = name;
fileData[1] = size;
fileData[2] = lastmod;
fileData[3] = link;
}
fileList.sort(getSort());
//document.write(getSort());
for(i=0; i<fileList.length; i++){ //length is the same as count($array)
fileData = fileList[i];
name = fileData[0];
size = fileData[1];
lastmod = fileData[2];
link = fileData[3];
res = res + getSpace(size,15) +size + " B ";
res = res + " "+ getSpace(lastmod,20)+ lastmod + " ";
res = res + " "+ link+ getSpace(name,50) + " ";
res = res + "<BR>";
}
document.getElementById('bucket_list').innerHTML = "<PRE>"+getLink()+"<BR>"+res+"</PRE>" ;
}
}
function getQueryVariable(variable) {
var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i=0;i<vars.length;i++) {
var pair = vars[i].split("=");
if (pair[0] == variable) {
return pair[1];
}
}
return null;
}
function sortSize(a,b) {
if(parseInt(a[1]) > parseInt(b[1])) return 1;
if(parseInt(a[1]) < parseInt(b[1])) return -1;
return 0;
}
function sortSizeDesc(a,b) { return (-sortSize(a,b)); }
function sortLastmod(a,b) {
if(a[2] > b[2]) return 1;
if(a[2] < b[2]) return -1;
return 0;
}
function sortLastmodDesc(a,b) { return (-sortLastmod(a,b)); }
function sortName(a,b) {
if(a[0] > b[0]) return 1;
if(a[0] < b[0]) return -1;
return 0;
}
function sortNameDesc(a,b) { return -sortName(a,b); }
//document.write('http://'+location.hostname);
function getSort(){
var s = getQueryVariable("sort");
var d = getQueryVariable("sortdir");
if(s=='size'){ return d == 'desc' ? sortSizeDesc : sortSize};
if(s=='name'){ return d == 'desc' ? sortNameDesc : sortName};
if(s=='lastmod'){ return d == 'desc' ? sortLastmodDesc : sortLastmod};
return sortName;
}
function getLink(){
return " "+getLinkSize() + " " + getLinkLastmod() + " " + getLinkName() + " " ;
}
function getNextSortDir(sortCol){
if (sortCol == getQueryVariable("sort"))
return getQueryVariable("sortdir") == 'desc' ? 'asc' : 'desc';
return 'asc'
}
function getLinkSize(){
return "<A HREF=\"?sort=size&sortdir=" +getNextSortDir('size') +"\">Size</A>";
}
function getLinkName(){
return "<A HREF=\"?sort=name&sortdir=" +getNextSortDir('name') +"\">Name</A>";
}
function getLinkLastmod(){
return "<A HREF=\"?sort=lastmod&sortdir=" +getNextSortDir('lastmod') +"\">Lastmodified</A>";
}
</SCRIPT>
</head>
<body onLoad="getList();">
<header>
<div class="header-left">
<h1>webfonts</h1>
</div>
<div class="header-right">
<code>@import <span class="string">"https://unique-address.cloudfront.net/font-name.css"</span>;</code>
</div>
</header>
<div id="bucket_list">
<!--This is where we'll be displaying the products once they're loaded-->
</div>
<div style="text-align: center;"><a class="question" href="http://team.agencyrevolution.com/wiki/cid/397">?</a></div>
<BR>
<SMALL>
<PRE>
Amazon S3 Bucket list v 1.1
</PRE>
</SMALL>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment