• twitter widget

    $("iframe#twitter-widget-0").contents().find('head').append('<style>img.u-photo.avatar{display:none !important;}.header.h-card.p-author{padding-left:0;}</style>');

    i use the “waituntilexists.js” plugin to detect when the content is added to DOM instead of the setTimout(): https://gist.github.com/buu700/4200601

    $("iframe#twitter-widget-0").waitUntilExists(function(){
    $("iframe#twitter-widget-0").contents().find('head').append('<style>img.u-photo.avatar{display:none !important;}.header.h-card.p-author{padding-left:0;}</style>');
    });


  • Chrome, Safari notifikācijas

    function notify(html) {
    var havePermission = window.webkitNotifications.checkPermission();
    if (havePermission == 0) {
    // 0 is PERMISSION_ALLOWED
    var notification = window.webkitNotifications.createNotification(
    'http://www.kautkas/abc.jpg',
    'title',
    ' description'
    );

    notification.onclick = function () {
    //window.open("http://www.linksuzurli.lv");
    notification.cancel();
    }
    notification.show();
    // Hide the notification after the timeout
    setTimeout(function(){
    notification.cancel()
    }, 30000);

    } else {
    window.webkitNotifications.requestPermission();
    }
    }


  • Login with Facebook – tas patiesībā ir graujoši vienkārši

    Pirmā koda daļa nodrošina pliku pieslēgšanos.
    Atliek vien noreģistrēt savu websaitu “facebook apps” un iegūt APP_ID, APP_SECRET utt.
    <fb:login-button autologoutlink="true" style="display:table-cell;padding:3px;" ></fb:login-button>
    <p><fb:like></fb:like></p>
    <div id="fb-root"></div>
    <script>
    window.fbAsyncInit = function() {
    FB.init({appId: '235xxxxxxxxxxxxxxx', status: true, cookie: true,
    xfbml: true});
    };
    (function() {
    var e = document.createElement('script');
    e.type = 'text/javascript';
    e.src = document.location.protocol +
    '//connect.facebook.net/lv_LV/all.js';
    e.async = true;
    document.getElementById('fb-root').appendChild(e);
    }());
    </script>

    Lai tiktu pie lietotāja Facebook datiem… spēlējamies tālāk…

    <?php
    define('YOUR_APP_ID', '235xxxxxxxxxxxxxxx');
    define('YOUR_APP_SECRET', 'c9fb5xxxxxxxxxxxxxxxxxxxxxxxxx');

    function get_facebook_cookie($app_id, $app_secret) {
    $args = array();
    parse_str(trim($_COOKIE['fbs_' . $app_id], '\\"'), $args);
    ksort($args);
    $payload = '';
    foreach ($args as $key => $value) {
    if ($key != 'sig') {
    $payload .= $key . '=' . $value;
    }
    }
    if (md5($payload . $app_secret) != $args['sig']) {
    return null;
    }
    return $args;
    }

    $cookie = get_facebook_cookie(YOUR_APP_ID, YOUR_APP_SECRET);

    $user = json_decode(file_get_contents(
    'https://graph.facebook.com/me?access_token=' .
    $cookie['access_token']));

    ?>
    <?php if ($cookie) { ?>
    Welcome <?= $user->name ?>
    <?php print_r($user); ?>
    <?php } else { ?>
    <fb:login-button></fb:login-button>
    <?php } ?>
    <div id="fb-root"></div>
    <script src="http://connect.facebook.net/en_US/all.js"></script>
    <script>
    FB.init({appId: '<?= YOUR_APP_ID ?>', status: true,
    cookie: true, xfbml: true});
    FB.Event.subscribe('auth.login', function(response) {
    window.location.reload();
    });
    </script>