Skip to content

Instantly share code, notes, and snippets.

@keiya
Created September 7, 2012 08:47
Show Gist options
  • Select an option

  • Save keiya/3664427 to your computer and use it in GitHub Desktop.

Select an option

Save keiya/3664427 to your computer and use it in GitHub Desktop.
ブラウザ閲覧中のタブ一覧をPHPに送って、HTMLで一覧が見れるやつ
// サーバ側
// touch dat.php && chmod 666 dat.php
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$fp = fopen('dat.csv','w');
if ($fp === FALSE) {
die();
}
foreach ($_POST as $key => $post) {
$list = array(htmlspecialchars($key),htmlspecialchars($post));
fputcsv($fp,$list);
}
header('Location:.');
}
else {
$fp = fopen('dat.csv','r');
if ($fp === FALSE) {
die();
}
$list = array();
while (($data = fgetcsv($fp,1000,",")) !== FALSE) {
$list[] = $data;
}
if (isset ($_GET['json']) && $_GET['json'] == 1) {
header('Content-type:application/json');
echo json_encode($list);
}
else {
$html = '';
foreach ($list as $val) {
$fragment = parse_url($val[1]);
$html .= '<dt><a href="'.$val[1].'" target="blank">'.$val[0].'</a></dt><dd>'.$fragment['host'].'</dd>';
}
?>
<!DOCTYPE html>
<html>
<head></head>
<body>
<dl>
<?php echo $html; ?>
</dl>
<form action='.' method='post'>
<input name='1' type='text' />
<input type='submit'>
</form>
</body>
</html>
<?php
}
}
fclose($fp);
// Firefoxアドオン側
exports.main = function() {};
var data = require("self").data;
var request = require("request");
var widget = require("widget").Widget({
id: "mozilla-link",
label: "Send tabs",
contentURL: "http://www.mozilla.org/favicon.ico",
onClick: listTabs
});
function listTabs() {
var tabs = require("tabs");
var str = '';
var sendtab = {};
for each (var tab in tabs) {
sendtab[tab.title] = tab.url;
}
request.Request({
url : "http://web.missinglink.co.jp/clip/",
content:sendtab,
}).post();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment