Skip to content

Instantly share code, notes, and snippets.

@mallowlabs
Created April 26, 2009 11:50
Show Gist options
  • Save mallowlabs/102017 to your computer and use it in GitHub Desktop.
Save mallowlabs/102017 to your computer and use it in GitHub Desktop.
<?xml version="1.0" encoding="UTF-8"?>
<Module>
<ModulePrefs title="Dokusyo Meter" author_email="mallowlabs@gmail.com">
<Require feature="opensocial-0.8" />
</ModulePrefs>
<Content type="html" view="profile,canvas,home">
<![CDATA[
<style type="text/css">
a img { border-style: none; }
</style>
<script type="text/javascript">
function validate(value) {
return value.match(/^(\d)+$/) != null;
}
function read(key, display) {
var request = opensocial.newDataRequest();
request.add(request.newFetchPersonRequest(
opensocial.IdSpec.PersonId.OWNER), "owner");
var owner = {};
owner[opensocial.IdSpec.Field.USER_ID] = opensocial.IdSpec.PersonId.OWNER;
request.add(request.newFetchPersonAppDataRequest(
opensocial.newIdSpec(owner), key), key + "Data");
request.send(function (response) {
var ownerData = response.get(key + "Data").getData();
var owner = response.get("owner").getData();
var needData = ownerData[owner.getId()];
if (!!needData) display(needData[key]);
});
}
function onread(needData) {
if (!validate(needData)) return;
var main = document.getElementById("gadget_main");
main.removeChild(main.firstChild);
var a = document.createElement("a");
a.setAttribute("href", "http://book.akahoshitakuya.com/u/" + needData);
a.setAttribute("target", "_blank");
var img = document.createElement("img");
img.setAttribute("src", "http://book.akahoshitakuya.com/bp_image/125/" + needData + ".jpg");
a.appendChild(img);
main.appendChild(a);
}
</script>
]]>
</Content>
<Content type="html" view="profile,canvas">
<![CDATA[
<div id="gadget_main" style="text-align:center" align="center"><p>ユーザIDが設定されていません</p></div>
<script type="text/javascript">
read("dokusyo_meter_id", onread);
</script>
]]>
</Content>
<Content type="html" view="home">
<![CDATA[
<script type="text/javascript">
function write(key, value) {
var req = opensocial.newDataRequest();
req.add(req.newUpdatePersonAppDataRequest(
opensocial.IdSpec.PersonId.VIEWER, key, value));
req.send();
}
function config_submit_onclick(e) {
var value = document.getElementById("dokusyo_meter_user_id").value;
if (validate(value)) {
write("dokusyo_meter_id", value);
onread(value);
} else {
alert("ID が不正です。数字のみが入力できます。");
}
return false;
}
read("dokusyo_meter_id", function(needData) {
if (!validate(needData)) return;
document.getElementById("dokusyo_meter_user_id").setAttribute("value", needData);
onread(needData);
});
</script>
<div id="gadget_main" style="text-align:center" align="center">&nbsp;</div>
<div id="config" style="margin-top:5px;text-align:center">
<form onsubmit="return config_submit_onclick(this)">
<input type="text" name="userid" id="dokusyo_meter_user_id"></input>
<input type="submit" value="ユーザID設定" class="formBt01" />
</form>
</div>
]]>
</Content>
</Module>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment