Forked from youpy/appjetcom_post_changes_to_gist.user.js
Created
March 21, 2009 09:40
-
-
Save satyr/82794 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 Appjet Gist Sync | |
// @description Syncs Appjet publishing to Gist posting/updating | |
// @namespace http://d.hatena.ne.jp/murky-satyr | |
// @name$pace http://d.hatena.ne.jp/youpy/ | |
// @include http://appjet.com/app/*/ide | |
// ==/UserScript== | |
if(top !== self) return; | |
const {URL} = document, [AppID] = /\d+/(URL); | |
var gistID = GM_getValue(AppID); | |
with(document.getElementById('publishbutton')){ | |
textContent += ' and '+ (gistID ? 'Update Gist '+ gistID : 'Post to Gist'); | |
addEventListener('click', sync, true); | |
} | |
function sync(e){ | |
const AppName = document.getElementById('publishedappname').value; | |
var me = this; | |
GM_xmlhttpRequest({ | |
method: 'get', | |
url: URL.replace(/[^\/]+$/, 'rawcode'), | |
onload: function(res){ | |
var span = me.parentNode.insertBefore(document.createElement('span'), | |
me.nextSibling); | |
span.appendChild(new Image).src = '/img/status-ball.gif'; | |
gist({ | |
id: gistID, | |
name: AppName +'.app.js', | |
code: res.responseText, | |
load: function(res){ | |
if(res.status === 200){ | |
var id = gistID = (/\d+$/(res.finalUrl) || [''])[0]; | |
GM_setValue(AppID, id); | |
GM_log(id); | |
span.innerHTML = | |
' '+ /<a [^>]*?class="id"[^>]*>\w+<\/a>/(res.responseText); | |
} else { | |
GM_log('Error: '+ res.status +' '+ res.statusText + | |
' ('+ res.finalUrl +')'); | |
span.innerHTML = 'error'.italics(); | |
} | |
}})}}); | |
} | |
function gist({id, name, code, load, index}){ | |
index || (index = 1); | |
GM_xmlhttpRequest({ | |
method: 'post', | |
url: 'http://gist.github.com/gists/'+ (id || ''), | |
data: ['file_'+ key +'[gistfile'+ index +']='+ encodeURIComponent(val) | |
for each([key, val] in | |
Iterator({ext: '', name: name, contents: code})) | |
].concat(id && '_method=put').join('&'), | |
headers: {'Content-type': 'application/x-www-form-urlencoded'}, | |
onload: load }); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment