forked from duckduckgo/zeroclickinfo-goodies
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request duckduckgo#1172 from duckduckgo/mattr/screen-resol…
…ution Created ScreenResolution, to view your resolution
- Loading branch information
Showing
3 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |