|
// ==UserScript== |
|
// @name gist raw perm HEAD |
|
// @namespace http://www.hatena.ne.jp/noromanba/ |
|
// @description add permanently HEAD link on Gist for UserScript |
|
// @include https://gist.github.com/* |
|
// @exclude https://gist.github.com/*/*/revisions |
|
// @grant none |
|
// @version 2014.12.20.0 |
|
// @homepage https://gist.github.com/2370972 |
|
// @downloadURL https://gist.github.com/noromanba/2370972/raw/gist-raw-perm-HEAD.user.js |
|
// @license MIT License http://nrm.mit-license.org/2012 |
|
// @author noromanba http://noromanba.flavors.me |
|
// @icon https://upload.wikimedia.org/wikipedia/commons/thumb/9/9b/Color_icon_orange_v2.svg/32px-Color_icon_orange_v2.svg.png |
|
// @icon64 https://upload.wikimedia.org/wikipedia/commons/thumb/9/9b/Color_icon_orange_v2.svg/64px-Color_icon_orange_v2.svg.png |
|
// ==/UserScript== |
|
|
|
// Icon (PD by Mizunoryu, Badseed, Jacobolus) |
|
// https://commons.wikimedia.org/wiki/File:Color_icon_orange_v2.svg |
|
|
|
// Devel |
|
// https://gist.github.com/2370972 |
|
|
|
(function () { |
|
// WIP |
|
// - [x] works well onload/DOMContentLoaded |
|
// - [ ] pjax:success/end handling |
|
// - can not use executeBrowserContext() (aka contentEval et al.) |
|
// - due to CSP, too much strict |
|
// - so can not touch page-context jQuery |
|
|
|
var appendButton = function code() { |
|
var links; |
|
if (!/^https:\/\/gist\.github\.com\/[\w-]+\/\w+/.test(location.href) || |
|
!(links = document.body.querySelectorAll('.files .raw-url:not(.head-url)'))) { |
|
return; |
|
} |
|
|
|
Array.prototype.forEach.call(links, function (hashlink) { |
|
// <a aria-label="View Raw" href="/noromanba/2370972/raw/431c256a6a929a15867112d93bc82238a2723a47/README.md" data-skip-pjax="" class="minibutton raw-url js-view-raw">Raw</a> |
|
var perm = document.createElement('a'); |
|
perm.textContent = 'HEAD'; |
|
perm.ariaLabel = 'View HEAD'; |
|
perm.dataset.skipPjax = ''; |
|
perm.classList.add('minibutton', 'head-url'); |
|
|
|
var pathnames = hashlink.href.split('/'); |
|
var filename = pathnames.pop(); |
|
var base = pathnames.slice(0, -1).join('/'); |
|
perm.title = filename; |
|
//perm.textContent = filename; |
|
perm.href = base + '/' + filename; |
|
|
|
hashlink.parentNode.appendChild(perm); |
|
}); |
|
}; |
|
appendButton(); |
|
|
|
// FIXME faild due to CSP, work w/ executeBrowserContext() |
|
/*/ |
|
// TODO independent of jQuery; replace to MutationObserver |
|
// c.f. https://github.com/defunkt/jquery-pjax#events |
|
jQuery('#js-pjax-container').on('pjax:end', function () { |
|
appendButton(); |
|
}); |
|
//*/ |
|
|
|
// FIXME 100% cpu usage |
|
/*/ |
|
// c.f. MutationObserver |
|
// https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver |
|
// http://caniuse.com/#feat=mutationobserver |
|
new MutationObserver(function (records) { |
|
//records.forEach(function (record) { |
|
appendButton(); |
|
//}); |
|
}).observe(document.body, { childList: true, subtree: true }); |
|
//*/ |
|
|
|
//////////////////////////////////////////////////////////////////////////// |
|
// DBG pjax handling |
|
// - https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js |
|
// - https://raw.github.com/defunkt/jquery-pjax/master/jquery.pjax.js |
|
/*/ |
|
window.addEventListener('load', function (evt) { |
|
console.info(evt.type, evt); |
|
}, false); |
|
window.addEventListener('popstate', function (evt) { |
|
console.info(evt.type, evt); |
|
}, false); |
|
|
|
// c.f. https://github.com/defunkt/jquery-pjax#events |
|
window.addEventListener('pjax:start', function (evt) { |
|
console.log(evt.type, evt); |
|
}, false); |
|
window.addEventListener('pjax:end', function (evt) { |
|
console.log(evt.type, evt); |
|
}, false); |
|
window.addEventListener('pjax:beforeSend', function (evt) { |
|
console.log(evt.type, evt); |
|
}, false); |
|
window.addEventListener('pjax:send', function (evt) { |
|
console.log(evt.type, evt); |
|
}, false); |
|
window.addEventListener('pjax:complete', function (evt) { |
|
console.log(evt.type, evt); |
|
}, false); |
|
window.addEventListener('pjax:success', function (evt) { |
|
console.log(evt.type, evt); |
|
}, false); |
|
window.addEventListener('pjax:error', function (evt) { |
|
console.log(evt.type, evt); |
|
}, false); |
|
window.addEventListener('pjax:timeout', function (evt) { |
|
console.log(evt.type, evt); |
|
}, false); |
|
window.addEventListener('pjax:send', function (evt) { |
|
console.log(evt.type, evt); |
|
}, false); |
|
// $.pjax.submit only use of Gist c.f. https://github.com/defunkt/jquery-pjax#pjaxsubmit |
|
window.addEventListener('submit', function (evt) { |
|
console.log(evt.type, evt); |
|
}, false); |
|
|
|
////////// jQuery .on ////////// |
|
// c.f. https://github.com/defunkt/jquery-pjax#events |
|
$(document).on('pjax:start', function (evt) { |
|
console.log(evt.type, evt); |
|
}); |
|
$(document).on('pjax:end', function (evt) { |
|
console.log(evt.type, evt); |
|
}); |
|
$(document).on('pjax:beforeSend', function (evt) { |
|
console.log(evt.type, evt); |
|
}); |
|
$(document).on('pjax:send', function (evt) { |
|
console.log(evt.type, evt); |
|
}); |
|
$(document).on('pjax:complete', function (evt) { |
|
console.log(evt.type, evt); |
|
}); |
|
$(document).on('pjax:success', function (evt) { |
|
console.log(evt.type, evt); |
|
}); |
|
$(document).on('pjax:error', function (evt) { |
|
console.log(evt.type, evt); |
|
}); |
|
$(document).on('pjax:timeout', function (evt) { |
|
console.log(evt.type, evt); |
|
}); |
|
$(document).on('pjax:send', function (evt) { |
|
console.log(evt.type, evt); |
|
}); |
|
$(document).on('submit', function (evt) { |
|
console.log(evt.type, evt); |
|
}); |
|
|
|
// #js-pjax-container |
|
$('#js-pjax-container').on('submit', function (evt) { |
|
console.log(evt.type, evt); |
|
}); |
|
$('#js-pjax-container').on('pjax:start', function (evt) { |
|
console.log(evt.type, evt); |
|
}); |
|
$('#js-pjax-container').on('pjax:end', function (evt) { |
|
console.log(evt.type, evt); |
|
}); |
|
$('#js-pjax-container').on('pjax:beforeSend', function (evt) { |
|
console.log(evt.type, evt); |
|
}); |
|
$('#js-pjax-container').on('pjax:send', function (evt) { |
|
console.log(evt.type, evt); |
|
}); |
|
$('#js-pjax-container').on('pjax:complete', function (evt) { |
|
console.log(evt.type, evt); |
|
}); |
|
$('#js-pjax-container').on('pjax:success', function (evt) { |
|
console.log(evt.type, evt); |
|
}); |
|
$('#js-pjax-container').on('pjax:error', function (evt) { |
|
console.log(evt.type, evt); |
|
}); |
|
$('#js-pjax-container').on('pjax:timeout', function (evt) { |
|
console.log(evt.type, evt); |
|
}); |
|
$('#js-pjax-container').on('pjax:send', function (evt) { |
|
console.log(evt.type, evt); |
|
}); |
|
$('#js-pjax-container').on('submit', function (evt) { |
|
console.log(evt.type, evt); |
|
}); |
|
//*/ |
|
})(); // /anonwrap |
The new Gist broke your script \( ><)シ