Skip to content

Instantly share code, notes, and snippets.

View rskull's full-sized avatar

Ryota Mogi rskull

View GitHub Profile
@rskull
rskull / gist:1089981
Created July 18, 2011 16:14
外部リンクを自動検出して、新しいタブで開くようにしてくれるはずです。
//外部リンク自動判断スクリプト
onload = function () {
var CheckURL = document.links;
for(i=0;i<CheckURL.length;i++) {
var links = CheckURL[i].href.split('/');
if((links[0].match(/[http|s]:/)) && (location.hostname != links[2])) {
CheckURL[i].target = '_blank';
}
}
}
@rskull
rskull / imgcng.js
Created July 26, 2011 14:27
カーソルが乗った時画像を切り替える
//画像切り替え
//ImgCng('画像ID','切り替えたい画像名');
//例 : ImgCng('img','image/img2.jpg');
function ImgCng(id,img){
var cng1 = document.getElementById(id);
var cng2 = cng1.src;
cng1.onmouseover = function () {
cng1.src = img;
@rskull
rskull / strcng.js
Created July 26, 2011 14:25
カーソルが乗った時文字を切り替える
//文字切り替え
//StrCng('ID','切り替えたい文字');
function StrCng(id,st){
var cng1 = document.getElementById(id);
var cng2 = cng1.innerHTML;
cng1.onmouseover = function () {
cng1.innerHTML = st;
}
@rskull
rskull / gist:1118089
Created August 1, 2011 13:05
よく使うアレを使いやするしたものです
<?php
//$get = e($_GET['get']);
function e($str, $charset = 'UTF-8') {
return htmlspecialchars($str, ENT_QUOTES, $charset);
}
?>
@rskull
rskull / gist:1128098
Created August 5, 2011 17:52
今月のカレンダー
onload = function () {
var now = new Date();
var y = now.getFullYear();
var m = now.getMonth();
document.write(y+'年'+m+'月<br>');
for (i=1;i<=31;i++) {
var check = new Date(y, m, i);
if (check.getMonth() == m) {
var d = document.createTextNode(i);
document.body.appendChild(d);
@rskull
rskull / gist:1136916
Created August 10, 2011 14:30
入力案内スクリプト
//入力案内出力
function GidFm (id, on, out) {
var check = '';
var gf = document.getElementById(id);
var gfv = gf.value;
gf.style.color = out;
if (gf.type == 'password') {
gf.type = 'text';
check = 'pass';
}
@rskull
rskull / gist:1198058
Created September 6, 2011 16:28
ジャンケンの判定
// 0 = グー 1 = チョキ 2 = パー
function janken (me) {
//相手の手
var you = Math.floor(Math.random () * 3);
$('me').innerHTML = hand(me);
$('you').innerHTML = hand(you);
$('res').innerHTML = result(me, you);
}
//IDの取得
@rskull
rskull / gist:1200385
Created September 7, 2011 12:00
フェードさせるスクリプト
//IE非対応バージョンです。
function feedin (id, speed) {
//フェードさせたいところのID
var feed = document.getElementById(id);
var filter = 0;
//最初にフィルターを0に設定
feed.style.opacity = 0;
feed.style.MozOpacity = 0;
var timer = setInterval(function () {
//filter += 0.1 だとちゃんと計算されない
@rskull
rskull / gist:1209412
Created September 11, 2011 10:00
9500秒を何時間何分何秒に変換
<?php
//秒を時間に変換
function oclock ($s) {
$h = 0;
$m = 0;
while ($s >= 60) {
if ($s >= 3600) {
$s -= 3600;
$h++;
@rskull
rskull / gist:1212131
Created September 12, 2011 19:26
9500秒を時:分:秒に変換 [コードゴルフ]
<?$s=9500;$m=$s%3600;echo($s-$m)/3600,':'.floor($m/60).':'.$m%60;