Skip to content

Commit

Permalink
Merge pull request duckduckgo#1172 from duckduckgo/mattr/screen-resol…
Browse files Browse the repository at this point in the history
…ution

Created ScreenResolution, to view your resolution
  • Loading branch information
moollaza committed Jun 24, 2015
2 parents 88eac92 + c4abe24 commit 643b2d1
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 0 deletions.
39 changes: 39 additions & 0 deletions lib/DDG/Goodie/ScreenResolution.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package DDG::Goodie::ScreenResolution;
# ABSTRACT: Return the current screen resolution using javascript

use DDG::Goodie;
use strict;

zci answer_type => "screen_resolution";
zci is_cached => 1;

name "Screen Resolution";
description "Displays the current screen resolution using javascript";
primary_example_queries "screen resolution";
secondary_example_queries "what is my display resolution";
code_url "https://github.com/duckduckgo/zeroclickinfo-goodies/blob/master/lib/DDG/Goodie/ScreenResolution.pm";
attribution twitter => 'mattr555',
github => ['mattr555', 'Matt Ramina'];

triggers startend => "screen resolution", "display resolution", "resolution of my screen";

handle remainder => sub {
return unless /^((what\'?s|what is)?\s?(the|my|current))?$/;

return structured_answer => {
id => 'screen_resolution',
name => 'Screen Resolution',
data => {
title => "Your screen resolution is [Loading...]"
},
templates => {
group => 'icon',
item => 0,
options => {
moreAt => 0
}
}
};
};

1;
13 changes: 13 additions & 0 deletions share/goodie/screen_resolution/screen_resolution.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
DDH.screen_resolution = DDH.screen_resolution || {};

DDH.screen_resolution.build = function(ops){
var title = window.screen.width + ' × ' + window.screen.height,
sub = ['Your Screen Resolution'];
if (window.devicePixelRatio && window.devicePixelRatio > 1){
sub.push('Pixel Ratio: x' + window.devicePixelRatio);
}

ops.data.title = title;
ops.data.subtitle = sub;
return ops;
}
37 changes: 37 additions & 0 deletions t/ScreenResolution.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env perl

use strict;
use warnings;
use Test::More;
use DDG::Test::Goodie;

zci answer_type => "screen_resolution";
zci is_cached => 1;

my @answer = test_zci('Javascript required', structured_answer => {
id => 'screen_resolution',
name => 'Screen Resolution',
data => {
title => "Your screen resolution is [Loading...]"
},
templates => {
group => 'text',
item => 0,
options => {
moreAt => 0
}
}
});

ddg_goodie_test(
[qw( DDG::Goodie::ScreenResolution )],
'screen resolution' => @answer,
'what is my display resolution' => @answer,
'whats my screen resolution' => @answer,
'what is my screen resolution' => @answer,
'what is the resolution of my screen?' => @answer,
'my screen resolution' => @answer,
'blah blah screen resolution' => undef,
);

done_testing;

0 comments on commit 643b2d1

Please sign in to comment.